-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpfc_lnx_setup.sh
executable file
·74 lines (58 loc) · 2.33 KB
/
pfc_lnx_setup.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
#!/bin/bash
# syntax: $0 <node> <service-id> <proto> <service-ip> <service-port> <remote-tunnel-ip> <remote-tunnel-port> <foo-ip>
# 1) setup GUE tunnel
# 2) add routing to the tunnel
# 3) send GUE ping
STEPS=3
TUNNEL_PREFIX="10.2.1."
NODE=$1
SERVICE_ID=$2
PROTO=$3
SERVICE_IP=$4
SERVICE_PORT=$5
# following information should be retrieved later from GUE ping
TUNNEL_REMOTE_IP=$6
#TUNNEL_REMOTE_PORT=${TUNNEL_PORT}
TUNNEL_REMOTE_PORT=$7
FOO_IP=$8
#VERBOSE="1"
if [ "${VERBOSE}" ]; then
echo -e "\nPFC.LNX.ADD : NODE='${NODE}' SERVICE_ID='${SERVICE_ID}' PROTO='${PROTO}' SERVICE_IP='${SERVICE_IP}' SERVICE_PORT='${SERVICE_PORT}' TUNNEL_REMOTE_IP='${TUNNEL_REMOTE_IP}' TUNNEL_REMOTE_PORT='${TUNNEL_REMOTE_PORT}' FOO_IP='${FOO_IP}'"
fi
TUNNEL_PORT=6080
IFNAME="gue${SERVICE_ID}"
CHECK=`docker exec -it ${NODE} bash -c "ip addr" | grep ${IFNAME}`
if [ "${CHECK}" ] ; then
echo "Service ID ${SERVICE_ID} already exist"
exit 1
fi
# careful! works only with small numbers
TUNNEL_LOCAL_IP=${TUNNEL_PREFIX}${SERVICE_ID}
echo -e "\n==============================================="
echo "# PFC.LNX.ADD [1/${STEPS}] : Create GUE tunnel (${IFNAME}) to ${TUNNEL_REMOTE_IP}:${TUNNEL_REMOTE_PORT})"
docker exec -it ${NODE} bash -c "ip fou add port ${TUNNEL_PORT} gue"
docker exec -it ${NODE} bash -c "ip link add name ${IFNAME} type ipip remote ${TUNNEL_REMOTE_IP} encap gue encap-sport ${TUNNEL_PORT} encap-dport ${TUNNEL_REMOTE_PORT}"
CHECK=`docker exec -it ${NODE} bash -c "ip link" | grep ${IFNAME}`
if [ ! "${CHECK}" ] ; then
echo "FAILED to create tunnel"
exit 1
fi
echo -e "\n==============================================="
echo "# PFC.LNX.ADD [2/${STEPS}] : Assign IP ${TUNNEL_LOCAL_IP} to ${IFNAME} and bring it up"
docker exec -it ${NODE} bash -c "ip addr add ${TUNNEL_LOCAL_IP}/24 dev ${IFNAME}"
docker exec -it ${NODE} bash -c "ip link set ${IFNAME} up"
# check
if [ "${VERBOSE}" ]; then
echo ""
docker exec -it ${NODE} bash -c "ip addr"
fi
echo -e "\n==============================================="
echo "# PFC.LNX.ADD [3/${STEPS}] : Set Route for service ${FOO_IP}/32 via ${IFNAME}"
docker exec -it ${NODE} bash -c "ip route add ${FOO_IP}/32 dev ${IFNAME}"
# check
if [ "${VERBOSE}" ]; then
echo ""
docker exec -it ${NODE} bash -c "ip route"
fi
echo -e "\n==============================================="
echo "# PFC.LNX.ADD : DONE"