1 # Copyright (c) 2024 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
16 # This library defines functions used by multiple entry scripts.
17 # Deliberately not depending on common.sh to allow standalone usage.
18 # Keep functions ordered alphabetically, please.
20 function activate_wrapper () {
22 # Acts as wrapper for activate docker topology.
25 # - ${1} - Node multiplicity of desired testbed.
26 # - ${2} - Node flavor string, usually describing the processor.
27 # - ${3} - CSIT-SUT-DCR image name and version.
32 get_available_interfaces "${1}" "${2}" || die
33 bind_dut_interfaces_to_vpp_driver || die
34 start_topology_containers "${3}" || die
35 bind_interfaces_to_containers || die
36 set_env_variables || die
37 print_env_variables || die
42 function bind_dut_interfaces_to_vpp_driver () {
44 # Bind DUT network interfaces to the driver that vpp will use
47 # - DUT1_NETDEVS - List of network devices allocated to DUT1 container.
49 # - NETDEV - Linux network interface.
50 # - DRIVER - Kernel driver to bind the interface to.
51 # - KRN_DRIVER - The original kernel driver of the network interface.
53 for NETDEV in "${DUT1_NETDEVS[@]}"; do
56 if [[ ${KRN_DRIVER} == "iavf" ]]; then
59 bind_interfaces_to_driver || die
65 function bind_interfaces_to_containers () {
67 # Bind linux network interface to container and create symlink for PCI
68 # address in container.
71 # - DCR_UUIDS - Docker Container UUIDs.
72 # - DCR_CPIDS - Docker Container PIDs (namespaces).
73 # - DUT1_NETDEVS - List of network devices allocated to DUT1 container.
74 # - PCI_ADDR - PCI address of network device.
75 # - TG_NETDEVS - List of network devices allocated to TG container.
77 # - NETDEV - Linux network interface.
78 # - KRN_DRIVER - Kernel driver of network device.
82 for PCI_ADDR in "${TG_PCIDEVS[@]}"; do
83 get_netdev_name || die
84 link_target=$(readlink -f /sys/bus/pci/devices/"${PCI_ADDR}") || {
85 die "Reading symlink for PCI address failed!"
87 cmd="ln -s ${link_target} /sys/bus/pci/devices/${PCI_ADDR}"
89 docker exec "${DCR_UUIDS[tg]}" ${cmd} || {
90 die "Linking PCI address in container failed!"
93 sudo ip link set ${NETDEV} netns ${DCR_CPIDS[tg]} || {
94 die "Moving interface to ${DCR_CPIDS[tg]} namespace failed!"
97 for PCI_ADDR in "${DUT1_PCIDEVS[@]}"; do
98 link_target=$(readlink -f /sys/bus/pci/devices/"${PCI_ADDR}") || {
99 die "Reading symlink for PCI address failed!"
101 cmd="ln -s ${link_target} /sys/bus/pci/devices/${PCI_ADDR}"
103 docker exec "${DCR_UUIDS[dut1]}" ${cmd} || {
104 die "Linking PCI address in container failed!"
108 if [[ ${KRN_DRIVER} != "vfio-pci" ]]; then
109 get_netdev_name || die
110 sudo ip link set ${NETDEV} netns ${DCR_CPIDS[dut1]} || {
111 die "Moving interface to ${DCR_CPIDS[dut1]} namespace failed!"
118 function bind_interfaces_to_driver () {
120 # Bind network interface specified by parameter to driver specified by
124 # - ADDR - PCI address of network interface.
125 # - DRIVER - Kernel driver.
129 pci_path="/sys/bus/pci/devices/${ADDR}"
130 drv_path="/sys/bus/pci/drivers/${DRIVER}"
131 if [ -d "${pci_path}/driver" ]; then
132 echo ${ADDR} | sudo tee ${pci_path}/driver/unbind > /dev/null || {
133 die "Failed to unbind interface ${ADDR}!"
137 echo ${DRIVER} | sudo tee /sys/bus/pci/devices/${ADDR}/driver_override \
139 die "Failed to override driver to ${DRIVER} for ${ADDR}!"
142 echo ${ADDR} | sudo tee ${drv_path}/bind > /dev/null || {
143 die "Failed to bind interface ${ADDR}!"
146 echo | sudo tee /sys/bus/pci/devices/${ADDR}/driver_override > /dev/null \
147 || die "Failed to reset driver override for ${ADDR}!"
151 function clean_environment () {
153 # Cleanup environment by removing topology containers and shared volumes
154 # and binding interfaces back to original driver.
157 # - DCR_UUIDS - Docker Container UUIDs.
158 # - DUT1_PCIDEVS - List of PCI addresses of devices of DUT1 container.
159 # - TG_PCIDEVS - List of PCI addresses of devices of TG container.
161 # - ADDR - PCI address of network interface.
162 # - DRIVER - Kernel driver.
166 # Kill docker containers.
167 docker rm --force "${DCR_UUIDS[@]}" || die "Cleanup containers failed!"
169 # Check if there are some leftover containers and remove all. Command will
170 # not fail in case there are no containers to remove.
171 docker rm --force $(docker ps -q --filter name=${DCR_UUIDS[dut1]}) || {
172 warn "Failed to remove hanged containers or nothing to remove!"
175 # Rebind interfaces back to kernel drivers.
177 for ADDR in ${TG_PCIDEVS[@]}; do
178 DRIVER="${TG_DRIVERS[${i}]}"
179 bind_interfaces_to_driver || die
183 for ADDR in ${DUT1_PCIDEVS[@]}; do
184 DRIVER="${DUT1_DRIVERS[${i}]}"
185 bind_interfaces_to_driver || die
191 function clean_environment_on_exit () {
193 # Cleanup environment by removing topology containers and binding
194 # interfaces back to original driver only if exit code is not 0.
195 # This function acts as workaround as 'set -eu' does not trigger ERR trap.
199 if [ $? -ne 0 ]; then
200 clean_environment || die
205 function deactivate_wrapper () {
207 # Acts as wrapper for deactivate docker topology.
210 # - ${@} - CSIT environment variables.
215 read_env_variables "${@}" || die
216 clean_environment || die
223 # Print the message to standard error end exit with error code specified
224 # by the second argument.
226 # Duplicate of common.sh function, as this file is also used standalone.
229 # - The default error message.
231 # - ${1} - The whole error message, be sure to quote. Optional
232 # - ${2} - the code to exit with, default: 1.
236 warn "${1:-Unspecified run-time error occurred!}"
241 function enter_mutex () {
243 # Enter mutual exclusion for protecting execution from starvation and
249 mutex_file="/tmp/mutex_file"
252 exec {lock_fd}>${mutex_file} || {
253 die "Mutex enter failed!"
255 flock --timeout "${mutex_timeout}" "${lock_fd}" || {
256 die "Calling flock() failed!"
258 # ----------------------
259 # Enter mutex succeeded.
260 warn "Mutex enter succeeded for PID $$."
264 function exit_mutex () {
266 # Exit mutual exclusion.
270 # ---------------------
271 # Remove mutex so we are not blocking others anymore.
272 flock -u "${lock_fd}" || {
273 die "Mutex destroy failed!"
275 warn "Mutex leave succeeded for PID $$."
279 function get_available_interfaces () {
281 # Find and get available Virtual functions.
284 # - ${1} - Nodeness, as set by common.sh get_test_code.
285 # - ${2} - Flavor, as set by common.sh get_test_code.
287 # - DUT1_NETDEVS - List of network devices allocated to DUT1 container.
288 # - DUT1_PCIDEVS - List of PCI addresses allocated to DUT1 container.
289 # - DUT1_NETMACS - List of MAC addresses allocated to DUT1 container.
290 # - DUT1_DRIVERS - List of interface drivers to DUT1 container.
291 # - DUT1_VLANS - List of interface vlans to TG container.
292 # - DUT1_MODEL - List of interface models to TG container.
293 # - TG_NETDEVS - List of network devices allocated to TG container.
294 # - TG_PCIDEVS - List of PCI addresses allocated to TG container.
295 # - TG_NETMACS - List of MAC addresses allocated to TG container.
296 # - TG_DRIVERS - List of interface drivers to TG container.
297 # - TG_VLANS - List of interface vlans to TG container.
298 # - TG_MODEL - List of interface models to TG container.
302 # Following code is specifying VFs ID based on nodeness and flavor.
303 # As there is great variability in hardware configuration outside LF,
304 # from bootstrap architecture point of view these are considered as flavors.
305 # Anyone can override flavor for its own machine and add condition here.
306 # See http://pci-ids.ucw.cz/v2.2/pci.ids for more info.
307 case_text="${1}_${2}"
308 case "${case_text}" in
310 # Add Intel Corporation XL710/X710 Virtual Function to the
312 # Add Intel Corporation E810 Virtual Function to the
314 pci_id="0x154c\|0x1889"
315 tg_netdev=(ens1 enp134)
316 dut1_netdev=(ens5 enp175)
320 # Add Intel Corporation XL710/X710 Virtual Function to the
322 # Add MT2892 Family [ConnectX-6 Dx] Virtual Function to the
324 pci_id="0x154c\|0x101e"
325 tg_netdev=(enp1s0f0 enp1s0f1 enP1p1s0f0)
326 dut1_netdev=(enP3p2s0f0 enP3p2s0f1 enP1p1s0f1)
330 # Add Intel Corporation E810 Virtual Function to the
333 tg_netdev=(enp42s0 enp44s0)
334 dut1_netdev=(enp63s0 enp61s0)
338 # Add Intel Corporation 82545EM Gigabit Ethernet Controller to the
341 tg_netdev=(enp0s8 enp0s9)
342 dut1_netdev=(enp0s16 enp0s17)
346 die "Unknown specification: ${case_text}!"
349 # TG side of connections.
356 # DUT1 side of connections.
364 # Find the first ${device_count} number of available TG Linux network
365 # VF device names. Only allowed VF PCI IDs are filtered.
366 for netdev in ${tg_netdev[@]}
369 for netdev_path in $(grep -l "${pci_id}" \
370 /sys/class/net/${netdev}*/device/device \
373 if [[ ${ports} -lt ${ports_per_nic} ]]; then
374 tg_netdev_name=$(dirname ${netdev_path})
375 tg_netdev_name=$(dirname ${tg_netdev_name})
376 TG_NETDEVS+=($(basename ${tg_netdev_name}))
382 ports_per_device=$((${ports_per_nic}*${#tg_netdev[@]}))
383 if [[ ${#TG_NETDEVS[@]} -eq ${ports_per_device} ]]; then
389 for netdev in "${TG_NETDEVS[@]}"; do
390 # Find the index of selected tg netdev among tg_netdevs
391 # e.g. enp8s5f7 is a vf of netdev enp8s5 with index 11
392 # and the corresponding dut1 netdev is enp133s13.
393 while [[ "${netdev}" != "${tg_netdev[$i]}"* ]]; do
396 # Rename tg netdev to dut1 netdev
397 # e.g. enp8s5f7 -> enp133s13f7
398 DUT1_NETDEVS+=(${netdev/${tg_netdev[$i]}/${dut1_netdev[$i]}})
399 # Don't need to reset i, all netdevs are sorted.
402 for NETDEV in "${TG_NETDEVS[@]}"; do
408 TG_PCIDEVS+=(${PCI_ADDR})
409 TG_NETMACS+=(${MAC_ADDR})
410 TG_DRIVERS+=(${KRN_DRIVER})
411 TG_VLANS+=(${VLAN_ID})
412 TG_MODELS+=(${MODEL})
414 for NETDEV in "${DUT1_NETDEVS[@]}"; do
420 DUT1_PCIDEVS+=(${PCI_ADDR})
421 DUT1_NETMACS+=(${MAC_ADDR})
422 DUT1_DRIVERS+=(${KRN_DRIVER})
423 DUT1_VLANS+=(${VLAN_ID})
424 DUT1_MODELS+=(${MODEL})
427 # We need at least two interfaces for TG/DUT1 for building topology.
428 if [ "${#TG_NETDEVS[@]}" -lt 2 ] || [ "${#DUT1_NETDEVS[@]}" -lt 2 ]; then
429 die "Not enough linux network interfaces found!"
434 function get_krn_driver () {
436 # Get kernel driver from linux network device name.
439 # - PCI_ADDR - PCI address of network device.
441 # - KRN_DRIVER - Kernel driver of network device.
445 pci_path="/sys/bus/pci/devices/${PCI_ADDR}"
446 KRN_DRIVER="$(basename $(readlink -f ${pci_path}/driver))" || {
447 die "Failed to get kernel driver of PCI interface!"
452 function get_mac_addr () {
454 # Get MAC address from linux network device name.
457 # - NETDEV - Linux network device name.
459 # - MAC_ADDR - MAC address of network device.
463 if [ -d /sys/class/net/${NETDEV}/device ]; then
464 MAC_ADDR="$(</sys/class/net/${NETDEV}/address)" || {
465 die "Failed to get MAC address of linux network interface!"
471 function get_netdev_name () {
473 # Get Linux network device name.
476 # - PCI_ADDR - PCI address of the device.
478 # - NETDEV - Linux network device name.
482 if [ -d /sys/bus/pci/devices/${PCI_ADDR}/net ]; then
483 NETDEV="$(basename /sys/bus/pci/devices/${PCI_ADDR}/net/*)" || {
484 die "Failed to get Linux interface name of ${PCI_ADDR}"
490 function get_csit_model () {
492 # Get CSIT model name from linux network device name.
495 # - NETDEV - Linux network device name.
497 # - MODEL - CSIT model name of network device.
501 if [ -d /sys/class/net/${NETDEV}/device ]; then
502 ID="$(</sys/class/net/${NETDEV}/device/device)" || {
503 die "Failed to get device id of linux network interface!"
513 MODEL="Mellanox-CX6DX"
522 function get_pci_addr () {
524 # Get PCI address in <domain>:<bus:<device>.<func> format from linux network
528 # - NETDEV - Linux network device name.
530 # - PCI_ADDR - PCI address of network device.
534 if [ -d /sys/class/net/${NETDEV}/device ]; then
535 PCI_ADDR=$(basename $(readlink /sys/class/net/${NETDEV}/device)) || {
536 die "Failed to get PCI address of linux network interface!"
538 if [ ! -d /sys/bus/pci/devices/${PCI_ADDR} ]; then
539 die "PCI device ${PCI_ADDR} doesn't exist!"
542 die "Can't get device info of interface ${NETDEV}!"
547 function get_vfio_group () {
549 # Get the VFIO group of a pci device.
552 # - PCI_ADDR - PCI address of a device.
554 # - VFIO_GROUP - The VFIO group of the PCI device.
556 if [[ -d /sys/bus/pci/devices/${PCI_ADDR}/iommu_group ]]; then
557 VFIO_GROUP="$(basename\
558 $(readlink /sys/bus/pci/devices/${PCI_ADDR}/iommu_group)\
560 die "PCI device ${PCI_ADDR} does not have an iommu group!"
565 function get_vlan_filter () {
567 # Get VLAN stripping filter from PF searched by mac adress.
570 # - MAC_ADDR - MAC address of VF.
572 # - VLAN_ID - VLAN ids.
576 # Sed regular expression pattern.
577 exp="s/^.*vlan ([[:digit:]]+).*$/\1/"
578 VLAN_ID=$(ip link | grep vlan | grep ${MAC_ADDR} | sed -re "${exp}") || true
579 VLAN_ID="${VLAN_ID:-0}"
583 function installed () {
585 # Check if the given utility is installed. Fail if not installed.
587 # Duplicate of common.sh function, as this file is also used standalone.
590 # - ${1} - Utility to check.
592 # - 0 - If command is installed.
593 # - 1 - If command is not installed.
601 function parse_env_variables () {
603 # Parse environment variables.
605 # Variables read, set or exported: Multiple,
606 # see the code for the current list.
610 IFS=@ read -a TG_NETMACS <<< "${CSIT_TG_INTERFACES_PORT_MAC}"
611 IFS=@ read -a TG_PCIDEVS <<< "${CSIT_TG_INTERFACES_PORT_PCI}"
612 IFS=@ read -a TG_DRIVERS <<< "${CSIT_TG_INTERFACES_PORT_DRV}"
613 IFS=@ read -a TG_VLANS <<< "${CSIT_TG_INTERFACES_PORT_VLAN}"
614 IFS=@ read -a TG_MODELS <<< "${CSIT_TG_INTERFACES_PORT_MODEL}"
615 IFS=@ read -a DUT1_NETMACS <<< "${CSIT_DUT1_INTERFACES_PORT_MAC}"
616 IFS=@ read -a DUT1_PCIDEVS <<< "${CSIT_DUT1_INTERFACES_PORT_PCI}"
617 IFS=@ read -a DUT1_DRIVERS <<< "${CSIT_DUT1_INTERFACES_PORT_DRV}"
618 IFS=@ read -a DUT1_VLANS <<< "${CSIT_DUT1_INTERFACES_PORT_VLAN}"
619 IFS=@ read -a DUT1_MODELS <<< "${CSIT_DUT1_INTERFACES_PORT_MODEL}"
621 for port in $(seq "${#TG_NETMACS[*]}"); do
622 CSIT_TG_INTERFACES+=$(cat << EOF
624 mac_address: "${TG_NETMACS[$((port-1))]}"
625 pci_address: "${TG_PCIDEVS[$((port-1))]}"
626 link: "link$((port-1))"
627 model: ${TG_MODELS[$((port-1))]}
628 driver: "${TG_DRIVERS[$((port-1))]}"
629 vlan: ${TG_VLANS[$((port-1))]}
632 CSIT_TG_INTERFACES+=$'\n'
634 for port in $(seq "${#DUT1_NETMACS[*]}"); do
635 CSIT_DUT1_INTERFACES+=$(cat << EOF
637 mac_address: "${DUT1_NETMACS[$((port-1))]}"
638 pci_address: "${DUT1_PCIDEVS[$((port-1))]}"
639 link: "link$((port-1))"
640 model: ${DUT1_MODELS[$((port-1))]}
641 driver: "${DUT1_DRIVERS[$((port-1))]}"
642 vlan: ${DUT1_VLANS[$((port-1))]}
645 CSIT_DUT1_INTERFACES+=$'\n'
650 function print_env_variables () {
652 # Get environment variables prefixed by CSIT_.
656 env | grep CSIT_ || true
660 function read_env_variables () {
662 # Read environment variables from parameters.
665 # - ${@} - Variables passed as an argument.
666 # Variables read, set or exported: Multiple,
667 # see the code for the current list.
671 for param in "$@"; do
674 declare -gA DCR_UUIDS
675 DCR_UUIDS+=([tg]="${CSIT_TG_UUID}")
676 DCR_UUIDS+=([dut1]="${CSIT_DUT1_UUID}")
678 IFS=@ read -a TG_NETMACS <<< "${CSIT_TG_INTERFACES_PORT_MAC}"
679 IFS=@ read -a TG_PCIDEVS <<< "${CSIT_TG_INTERFACES_PORT_PCI}"
680 IFS=@ read -a TG_DRIVERS <<< "${CSIT_TG_INTERFACES_PORT_DRV}"
681 IFS=@ read -a TG_VLANS <<< "${CSIT_TG_INTERFACES_PORT_VLAN}"
682 IFS=@ read -a TG_MODELS <<< "${CSIT_TG_INTERFACES_PORT_MODEL}"
683 IFS=@ read -a DUT1_NETMACS <<< "${CSIT_DUT1_INTERFACES_PORT_MAC}"
684 IFS=@ read -a DUT1_PCIDEVS <<< "${CSIT_DUT1_INTERFACES_PORT_PCI}"
685 IFS=@ read -a DUT1_DRIVERS <<< "${CSIT_DUT1_INTERFACES_PORT_DRV}"
686 IFS=@ read -a DUT1_VLANS <<< "${CSIT_DUT1_INTERFACES_PORT_VLAN}"
687 IFS=@ read -a DUT1_MODELS <<< "${CSIT_DUT1_INTERFACES_PORT_MODEL}"
691 function set_env_variables () {
693 # Set environment variables.
696 # - DCR_UUIDS - Docker Container UUIDs.
697 # - DCR_PORTS - Docker Container's SSH ports.
698 # - DUT1_NETDEVS - List of network devices allocated to DUT1 container.
699 # - DUT1_PCIDEVS - List of PCI addresses allocated to DUT1 container.
700 # - DUT1_NETMACS - List of MAC addresses allocated to DUT1 container.
701 # - DUT1_DRIVERS - List of interface drivers to DUT1 container.
702 # - DUT1_VLANS - List of interface vlans to TG container.
703 # - DUT1_MODEL - List of interface models to TG container.
704 # - TG_NETDEVS - List of network devices allocated to TG container.
705 # - TG_PCIDEVS - List of PCI addresses allocated to TG container.
706 # - TG_NETMACS - List of MAC addresses allocated to TG container.
707 # - TG_DRIVERS - List of interface drivers to TG container.
708 # - TG_VLANS - List of interface vlans to TG container.
709 # - TG_MODEL - List of interface models to TG container.
714 CSIT_TG_HOST="$(hostname --all-ip-addresses | awk '{print $1}')" || {
715 die "Reading hostname IP address failed!"
717 CSIT_TG_PORT="${DCR_PORTS[tg]##*:}"
718 CSIT_TG_UUID="${DCR_UUIDS[tg]}"
719 CSIT_TG_ARCH="$(uname -i)" || {
720 die "Reading machine architecture failed!"
722 CSIT_DUT1_HOST="$(hostname --all-ip-addresses | awk '{print $1}')" || {
723 die "Reading hostname IP address failed!"
725 CSIT_DUT1_PORT="${DCR_PORTS[dut1]##*:}"
726 CSIT_DUT1_UUID="${DCR_UUIDS[dut1]}"
727 CSIT_DUT1_ARCH="$(uname -i)" || {
728 die "Reading machine architecture failed!"
732 CSIT_TG_INTERFACES_PORT_MAC="${TG_NETMACS[*]}"
733 CSIT_TG_INTERFACES_PORT_PCI="${TG_PCIDEVS[*]}"
734 CSIT_TG_INTERFACES_PORT_DRV="${TG_DRIVERS[*]}"
735 CSIT_TG_INTERFACES_PORT_VLAN="${TG_VLANS[*]}"
736 CSIT_TG_INTERFACES_PORT_MODEL="${TG_MODELS[*]}"
737 CSIT_DUT1_INTERFACES_PORT_MAC="${DUT1_NETMACS[*]}"
738 CSIT_DUT1_INTERFACES_PORT_PCI="${DUT1_PCIDEVS[*]}"
739 CSIT_DUT1_INTERFACES_PORT_DRV="${DUT1_DRIVERS[*]}"
740 CSIT_DUT1_INTERFACES_PORT_VLAN="${DUT1_VLANS[*]}"
741 CSIT_DUT1_INTERFACES_PORT_MODEL="${DUT1_MODELS[*]}"
747 function start_topology_containers () {
749 # Starts csit-sut-dcr docker containers for TG/DUT1.
752 # - CSIT_DIR - Path to existing root of local CSIT git repository.
754 # - DCR_UUIDS - Docker Container UUIDs.
755 # - DCR_PORTS - Docker Container SSH TCP ports.
756 # - DCR_CPIDS - Docker Container PIDs (namespaces).
760 if ! installed docker; then
761 die "Docker not present. Please install before continue!"
764 # If the IMAGE is not already loaded then docker run will pull the IMAGE,
765 # and all image dependencies, before it starts the container.
767 # Run the container in the background and print the new container ID.
768 dcr_stc_params="--detach=true "
769 # Give extended privileges to this container. A "privileged" container is
770 # given access to all devices and able to run nested containers.
771 dcr_stc_params+="--privileged "
772 # Publish all exposed ports to random ports on the host interfaces.
773 dcr_stc_params+="--publish-all "
774 # Automatically remove the container when it exits.
775 dcr_stc_params+="--rm "
777 dcr_stc_params+="--shm-size 2G "
778 # Override access to PCI bus by attaching a filesystem mount to the
780 dcr_stc_params+="--mount type=tmpfs,destination=/sys/bus/pci/devices "
781 # Mount vfio devices to be able to use VFs inside the container.
783 for PCI_ADDR in ${DUT1_PCIDEVS[@]}; do
785 if [[ ${KRN_DRIVER} == "vfio-pci" ]]; then
787 dcr_stc_params+="--device /dev/vfio/${VFIO_GROUP} "
791 if ! ${vfio_bound}; then
792 dcr_stc_params+="--volume /dev/vfio:/dev/vfio "
794 # Disable manipulation with hugepages by VPP.
795 dcr_stc_params+="--volume /dev/null:/etc/sysctl.d/80-vpp.conf "
796 # Mount docker.sock to be able to use docker deamon of the host.
797 dcr_stc_params+="--volume /var/run/docker.sock:/var/run/docker.sock "
798 # Mount /opt/boot/ where VM kernel and initrd are located.
799 dcr_stc_params+="--volume /opt/boot/:/opt/boot/ "
800 # Mount host hugepages for VMs.
801 dcr_stc_params+="--volume /dev/hugepages/:/dev/hugepages/ "
803 dcr_stc_params+="--sysctl net.ipv6.conf.all.disable_ipv6=1 "
804 dcr_stc_params+="--sysctl net.ipv6.conf.default.disable_ipv6=1 "
806 # Docker Container UUIDs.
807 declare -gA DCR_UUIDS
808 # Docker Container SSH TCP ports.
809 declare -gA DCR_PORTS
810 # Docker Container PIDs (namespaces).
811 declare -gA DCR_CPIDS
813 # Run TG and DUT1. As initial version we do support only 2-node.
814 params=(${dcr_stc_params} --name csit-tg-$(uuidgen) ${dcr_image})
815 DCR_UUIDS+=([tg]=$(docker run "${params[@]}")) || {
816 die "Failed to start TG docker container!"
818 params=(${dcr_stc_params} --name csit-dut1-$(uuidgen) ${dcr_image})
819 DCR_UUIDS+=([dut1]=$(docker run "${params[@]}")) || {
820 die "Failed to start DUT1 docker container!"
823 trap 'clean_environment_on_exit' EXIT || {
824 die "Trap attempt failed, please cleanup manually. Aborting!"
827 # Get Containers TCP ports.
828 params=(${DCR_UUIDS[tg]})
829 DCR_PORTS+=([tg]=$(docker port "${params[@]}")) || {
830 die "Failed to get port of TG docker container!"
832 params=(${DCR_UUIDS[dut1]})
833 DCR_PORTS+=([dut1]=$(docker port "${params[@]}")) || {
834 die "Failed to get port of DUT1 docker container!"
837 # Get Containers PIDs.
838 params=(--format="{{ .State.Pid }}" ${DCR_UUIDS[tg]})
839 DCR_CPIDS+=([tg]=$(docker inspect "${params[@]}")) || {
840 die "Failed to get PID of TG docker container!"
842 params=(--format="{{ .State.Pid }}" ${DCR_UUIDS[dut1]})
843 DCR_CPIDS+=([dut1]=$(docker inspect "${params[@]}")) || {
844 die "Failed to get PID of DUT1 docker container!"
849 # Print the message to standard error.
851 # Duplicate of common.sh function, as this file is also used standalone.
854 # - ${@} - The text of the message.