2 # COPYRIGHT NOTICE STARTS HERE
4 # Copyright 2019 Intel Co., Ltd.
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
10 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # COPYRIGHT NOTICE ENDS HERE
20 # This script prepares the runtime environment
21 # for running vIPSec shell scripts on Ubuntu 18.04
28 function setup_dependencies {
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 -
35 function install_vpp {
37 apt-get install -y vpp vpp-plugin-core vpp-plugin-dpdk
40 function install_dpdk {
42 git clone http://dpdk.org/git/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
46 insmod x86_64-native-linux-gcc/kmod/igb_uio.ko
49 function ipsec_settings {
50 # Create vpp configuration file
51 cat > /opt/config/vpp.config << EOF
53 exec /opt/config/ipsec.conf
55 cli-listen /run/vpp/cli.sock
67 no-tx-checksum-offload
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)
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)
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)
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
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
115 set interface ip address VirtualFunctionEthernet0/5/0 input_interface_ip/24
116 set interface ip address VirtualFunctionEthernet0/6/0 output_interface_ip/24
118 set int promiscuous on VirtualFunctionEthernet0/5/0
119 set int promiscuous on VirtualFunctionEthernet0/6/0
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
124 ip route add count 1 packet_dst/32 via route_interface VirtualFunctionEthernet0/6/0
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
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
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
157 echo 'vm.nr_hugepages = 1024' >> /etc/sysctl.conf