Update environment varables to match latest
[multicloud/k8s.git] / kud / tests / vIPSec / ipsec
1 #!/bin/bash
2 # COPYRIGHT NOTICE STARTS HERE
3 #
4 # Copyright 2019 Intel Co., Ltd.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17 #
18 # COPYRIGHT NOTICE ENDS HERE
19
20 # This script prepares the runtime environment
21 # for running vIPSec shell scripts on Ubuntu 18.04
22
23 set -o nounset
24 set -o pipefail
25 set -o xtrace
26 set -o errexit
27
28 function setup_dependencies {
29     apt-get update
30     apt-get install -y curl gnupg2 pciutils make gcc libnuma-dev python git linux-headers-`uname -r` module-init-tools libssl-dev
31     echo "deb [trusted=yes] https://packagecloud.io/fdio/release/ubuntu bionic main" >> /etc/apt/sources.list.d/99fd.io.list
32     curl -L https://packagecloud.io/fdio/master/gpgkey | apt-key add -
33 }
34
35 function install_vpp {
36     apt-get update
37     apt-get install -y vpp vpp-plugin-core vpp-plugin-dpdk
38 }
39
40 function install_dpdk {
41     cd /opt
42     git clone http://dpdk.org/git/dpdk
43     cd /opt/dpdk
44     export RTE_TARGET=x86_64-native-linux-gcc/ && export DESTDIR=/opt/dpdk && export RTE_SDK=/opt/dpdk &&  make install T=x86_64-native-linux-gcc
45     modprobe uio
46     insmod x86_64-native-linux-gcc/kmod/igb_uio.ko
47 }
48
49 function ipsec_settings {
50 # Create vpp configuration file
51     cat > /opt/config/vpp.config << EOF
52     unix {
53             exec /opt/config/ipsec.conf
54             nodaemon
55             cli-listen /run/vpp/cli.sock
56             log /tmp/vpp.log
57          }
58
59     cpu {
60            main-core 0
61            corelist-workers 1
62         }
63
64     dpdk {
65             socket-mem 512
66             log-level debug
67             no-tx-checksum-offload
68             dev default{
69                     num-tx-desc 512
70                     num-rx-desc 512
71             }
72             dev interfaceABus
73             {
74                     workers 0
75             }
76             dev interfaceBBus
77             {
78                     workers 0
79             }
80             vdev crypto_aesni_mb0
81
82             no-multi-seg
83
84             #enable_cryptodev
85
86          }
87 EOF
88
89 # Check if sriov and qat are enabled, bind the pci devices with igb_uio driver
90     if [ "$sriov_enabled" = true ]; then
91         export interfaceABus=$(lspci -D -nn | grep -m1 '8086:154c' | cut -d ' ' -f 1)
92         export interfaceBBus=$(lspci -D -nn | grep -m2 '8086:154c' | cut -d ' ' -f 1 | tail -n1)
93     else
94         export interfaceABus=$(ls -la /sys/class/net | grep 'eth1' | cut -d '/' -f 5)
95         export interfaceBBus=$(ls -la /sys/class/net | grep 'eth3' | cut -d '/' -f 5)
96     fi
97     sed -i -e "s/interfaceABus/${interfaceABus}/g" -e "s/interfaceBBus/${interfaceBBus}/g" /opt/config/vpp.config
98     python /opt/dpdk/usertools/dpdk-devbind.py -b igb_uio $interfaceABus $interfaceBBus
99     export interfaceA=$(vppctl sh int | awk '$2 == "1"' | cut -d ' ' -f 1)
100     export interfaceB=$(vppctl sh int | awk '$2 == "2"' | cut -d ' ' -f 1)
101
102     if [ "$qat_enabled" = true ]; then
103         export qatABus=$(lspci -D -nn | grep -m1 '8086:37c9' | cut -d ' ' -f 1)
104         export qatBBus=$(lspci -D -nn | grep -m2 '8086:37c9' | cut -d ' ' -f 1 | tail -n1)
105         python /opt/dpdk/usertools/dpdk-devbind.py -b igb_uio $qatABus $qatBBus
106         sed -i "/#enable_cryptodev/a\n              dev $qatABus\n              dev $qatBBus\n" /opt/config/vpp.config
107         sed -i "/vdev crypto_aesni_mb0/d" /opt/config/vpp.config
108     fi
109
110 # Create the sample ipsec configuration file
111     cat > /opt/config/ipsec.conf << EOF
112     set interface state VirtualFunctionEthernet0/5/0 up
113     set interface state VirtualFunctionEthernet0/6/0 up
114
115     set interface ip address VirtualFunctionEthernet0/5/0 input_interface_ip/24
116     set interface ip address VirtualFunctionEthernet0/6/0 output_interface_ip/24
117
118     set int promiscuous on VirtualFunctionEthernet0/5/0
119     set int promiscuous on VirtualFunctionEthernet0/6/0
120
121     set ip arp VirtualFunctionEthernet0/6/0 remote_tunnel_ip fa:16:3e:a6:e4:c7
122     set ip arp VirtualFunctionEthernet0/5/0 input_interface_ip fa:16:3e:f1:65:dc
123
124     ip route add count 1 packet_dst/32 via route_interface VirtualFunctionEthernet0/6/0
125
126     ipsec spd add 1
127     set interface ipsec spd VirtualFunctionEthernet0/6/0 1
128     ipsec sa add 1 spi 1921681003 esp tunnel-src output_interface_ip tunnel-dst remote_tunnel_ip crypto-key 2b7e151628aed2a6abf7158809cf4f3d crypto-alg aes-cbc-128 integ-key 6867666568676665686766656867666568676669 integ-alg sha1-96
129     ipsec policy add spd 1 traffic_direction priority 100 action protect sa 1 local-ip-range packet_src-packet_src remote-ip-range packet_dst-packet_dst
130     ipsec policy add spd 1 traffic_direction priority 90 protocol 50 action bypass local-ip-range packet_src-255.255.255.255 remote-ip-range remote_tunnel_ip-remote_tunnel_ip
131 EOF
132
133 # Replace all ip and interfaces inside the ipsec configuration file
134     sed -i -e "s/input_interface_ip/${input_interface_ip}/g" -e "s/output_interface_ip/${output_interface_ip}/g" -e "s/remote_tunnel_ip/${remote_tunnel_ip}/g" -e "s/route_interface/${route_interface}/g" -e "s#VirtualFunctionEthernet0/5/0#${interfaceA}#g" -e "s#VirtualFunctionEthernet0/6/0#${interfaceB}/g" -e "s/packet_src/${packet_src}/g" -e "s/packet_dst/${packet_dst}/g" -e "s/traffic_direction/${traffic_direction}/g" /opt/config/ipsec.conf
135     vpp -c /opt/config/vpp.config
136 }
137
138
139 mkdir /opt/config
140 echo "$demo_artifacts_version"                >  /opt/config/demo_artifacts_version.txt
141 echo "$dcae_collector_ip"                     >  /opt/config/dcae_collector_ip.txt
142 echo "$dcae_collector_port"                   >  /opt/config/dcae_collector_port.txt
143 echo "$ipsec_private_net_gw"                  >  /opt/config/ipsec_private_net_gw_ip.txt
144 echo "$ipsec_private_net_cidr"                >  /opt/config/ipsec_private_net_cidr.txt
145 echo "$ipsec_private_network_name"            >  /opt/config/ipsec_private_network_name.txt
146 echo "$packet_src"                            >  /opt/config/packet_source_ip.txt
147 echo "$packet_dst"                            >  /opt/config/packet_destination_ip.txt
148 echo "$remote_tunnel_ip"                      >  /opt/config/remote_tunnel.txt
149 echo "$route_interface"                       >  /opt/config/route_interface.txt
150 echo "$traffic_direction"                     >  /opt/config/traffic_direction.txt
151 echo "$vipsecA_private_ip_0"                  >  /opt/config/vipsecA_private_ip0.txt
152 echo "$vipsecA_private_ip_2"                  >  /opt/config/vipsecA_private_ip2.txt
153 echo "$protected_clientA_network_name"        >  /opt/config/protected_clientA_network_name.txt
154 echo "$protected_clientA_net_gw"              >  /opt/config/protected_clientA_net_gw.txt
155 echo "$protected_clientA_net_cidr"            >  /opt/config/protected_clientA_net_cidr.txt
156
157 echo 'vm.nr_hugepages = 1024' >> /etc/sysctl.conf
158 sysctl -p
159
160 setup_dependencies
161 install_vpp
162 install_dpdk
163 ipsec_settings