fix(ipsec): Prepare IPsecUtil for upcoming changes
[csit.git] / fdio.infra.ansible / roles / tg / files / csit-initialize-docker-tg.sh
1 #!/usr/bin/env bash
2
3 # Copyright (c) 2021 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 # CSIT SRIOV VF initialization and isolation.
17
18 set -euo pipefail
19
20 case "${1:-start}" in
21     "start" )
22         # Run TG
23         for cnt in $(seq 1 ${2:-1}); do
24             docker network create --driver bridge csit-nw-tg${cnt} || true
25             # If the IMAGE is not already loaded then docker run will pull the
26             # IMAGE, and all image dependencies, before it starts the container.
27             dcr_image="csit_sut-ubuntu2004:local"
28             # Run the container in the background and print the new container
29             # ID.
30             dcr_stc_params="--detach=true "
31             # Give extended privileges to this container. A "privileged"
32             # container is given access to all devices and able to run nested
33             # containers.
34             dcr_stc_params+="--privileged "
35             # Publish all exposed ports to random ports on the host interfaces.
36             dcr_stc_params+="--publish 600${cnt}:2222 "
37             # Automatically remove the container when it exits.
38             dcr_stc_params+="--rm "
39             # Size of /dev/shm.
40             dcr_stc_params+="--shm-size 4G "
41             # Mount vfio to be able to bind to see binded interfaces. We cannot
42             # use --device=/dev/vfio as this does not see newly binded
43             # interfaces.
44             dcr_stc_params+="--volume /dev:/dev "
45             # Mount /opt/boot/ where VM kernel and initrd are located.
46             dcr_stc_params+="--volume /opt:/opt "
47             # Mount host hugepages for VMs.
48             dcr_stc_params+="--volume /dev/hugepages:/dev/hugepages "
49
50             params=(${dcr_stc_params} --name csit-tg-"${cnt}" "${dcr_image}")
51             docker run --network=csit-nw-tg${cnt} "${params[@]}"
52         done
53         ;;
54     "stop" )
55         docker rm --force $(docker ps --all --quiet --filter name=csit)
56         docker network rm $(docker network ls --filter name=csit --quiet)
57         ;;
58 esac