forked from contiv/vpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-node.sh
172 lines (144 loc) · 4.22 KB
/
setup-node.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
#!/usr/bin/env bash
#confirm asks a question and based on user input it returns either 1-yes or 0-no.
confirm () {
while true
do
read -r -p "$1 [Y/n] " input
case $input in
[yY][eE][sS]|[yY])
echo 1
return
;;
[nN][oO]|[nN])
echo 0
return
;;
*)
;;
esac
done
}
#loads uio_pci_generic driver and setup the loading on each boot up if requested
installPCIUIO() {
modprobe uio_pci_generic
if [[ $(confirm "Do you want the PCI UIO driver to be loaded on boot up?") -eq 1 ]]; then
# check if the driver is not already added into the file
if ! grep -q "uio_pci_generic" /etc/modules; then
echo uio_pci_generic >> /etc/modules
echo "Module uio_pci_generic was added into /etc/modules"
fi
fi
}
#selects an interface that will be used for node interconnect
selectNodeIntreconnectIf() {
interfaces=`lshw -class network -businfo | grep pci`
if [[ -z "$interfaces" ]]; then
echo "No network devices found."
exit 1
fi
echo "The following network devices were found"
echo "$interfaces" | sed 's/pci@//g' | awk '{printf "%s) %s %s\n", NR, $2, $1}'
nicCnt=$(echo "$interfaces" | wc -l)
selectedDevice=0
#process input from user
while true
do
read -r -p "Select interface for node interconnect [1-$nicCnt]:" selection
case "$selection" in
[0-9]*)
if [[ "$selection" -gt "$nicCnt" || "$selection" -eq 0 ]]; then
echo "Selected option is out of range"
else
selectedDevice=$(echo "$interfaces" | sed "${selection}q;d")
break
fi
;;
*)
echo "Invalid input"
;;
esac
done
device=$(echo "$selectedDevice" | awk '{print $2}')
pciAddr=$(echo "$selectedDevice" | awk '{print $1}' | sed 's/pci@//g')
if [[ $(confirm "Device '$device' must be shutdown, do you want to proceed?") -ne 1 ]]; then
exit 1
fi
#check whether startup.conf exist
startup="
unix {
nodaemon
cli-listen /run/vpp/cli.sock
cli-no-pager
poll-sleep-usec 100
}
nat {
endpoint-dependent
translation hash buckets 1048576
translation hash memory 268435456
user hash buckets 1024
max translations per user 10000
}
acl-plugin {
use tuple merge 0
}
api-trace {
on
nitems 5000
}
dpdk {
dev $pciAddr
}
socksvr {
default
}
statseg {
default
}
"
echo "$startup"
if [[ $(confirm "File /etc/vpp/contiv-vswitch.conf will be modified, do you want to proceed?") -ne 1 ]]; then
exit 1
fi
#create vpp startup config
echo "$startup" > /etc/vpp/contiv-vswitch.conf
#shutdown interface
ip link set "$device" down
}
## Setup begins
echo "#########################################"
echo "# Contiv - VPP #"
echo "#########################################"
# Make sure only root can run this script
if [[ $EUID -ne 0 ]]; then
echo "ERROR: This script must be run as root." 1>&2
exit 1
fi
if [[ $(confirm "Do you want to setup multinode cluster?") -eq 1 ]]; then
kernelModule=$(lsmod | grep uio_pci_generic | wc -l)
if [[ $kernelModule -gt 0 ]]; then
echo "PCI UIO driver is loaded"
else
echo "PCI UIO driver is not loaded"
if [[ $(confirm "Do you want to load PCI UIO driver?") -eq 1 ]]; then
installPCIUIO
else
echo "Unless the driver is loaded, VPP will not be able to grab the NIC."
exit 0
fi
fi
selectNodeIntreconnectIf
fi
if [[ $(confirm "Do you want to pull the latest images?") -eq 1 ]]; then
bash <(curl -s https://raw.githubusercontent.com/contiv/vpp/master/k8s/pull-images.sh)
fi
if [[ $(docker ps | grep contiv-stn | wc -l) -gt 0 ]]; then
echo "STN Daemon is already running"
if [[ $(confirm "Do you want to restart STN Daemon?") -eq 1 ]]; then
docker stop contiv-stn
docker rm contiv-stn
bash <(curl -s https://raw.githubusercontent.com/contiv/vpp/master/k8s/stn-install.sh)
fi
elif [[ $(confirm "Do you want to install STN Daemon?") -eq 1 ]]; then
bash <(curl -s https://raw.githubusercontent.com/contiv/vpp/master/k8s/stn-install.sh)
fi
echo "Configuration of the node finished successfully."