Infra: Increase shm-size
[csit.git] / resources / libraries / bash / function / device.sh
1 # Copyright (c) 2021 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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 set -exuo pipefail
15
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.
19
20 function activate_wrapper () {
21
22     # Acts as wrapper for activate docker topology.
23     #
24     # Variables read:
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.
28
29     set -exuo pipefail
30
31     enter_mutex || die
32     get_available_interfaces "${1}" "${2}" || die
33     start_topology_containers "${3}" || die
34     bind_interfaces_to_containers || die
35     set_env_variables || die
36     print_env_variables || die
37     exit_mutex || die
38 }
39
40
41 function bind_interfaces_to_containers () {
42
43     # Bind linux network interface to container and create symlink for PCI
44     # address in container.
45     #
46     # Variables read:
47     # - DCR_UUIDS - Docker Container UUIDs.
48     # - DCR_CPIDS - Docker Container PIDs (namespaces).
49     # - DUT1_NETDEVS - List of network devices allocated to DUT1 container.
50     # - PCI_ADDR - PCI address of network device.
51     # - TG_NETDEVS - List of network devices allocated to TG container.
52     # Variables set:
53     # - NETDEV - Linux network interface.
54
55     set -exuo pipefail
56
57     for NETDEV in "${TG_NETDEVS[@]}"; do
58         get_pci_addr || die
59         link_target=$(readlink -f /sys/bus/pci/devices/"${PCI_ADDR}") || {
60             die "Reading symlink for PCI address failed!"
61         }
62         cmd="ln -s ${link_target} /sys/bus/pci/devices/${PCI_ADDR}"
63
64         sudo ip link set ${NETDEV} netns ${DCR_CPIDS[tg]} || {
65             die "Moving interface to ${DCR_CPIDS[tg]} namespace failed!"
66         }
67         docker exec "${DCR_UUIDS[tg]}" ${cmd} || {
68             die "Linking PCI address in container failed!"
69         }
70     done
71     for NETDEV in "${DUT1_NETDEVS[@]}"; do
72         get_pci_addr || die
73         link_target=$(readlink -f /sys/bus/pci/devices/"${PCI_ADDR}") || {
74             die "Reading symlink for PCI address failed!"
75         }
76         cmd="ln -s ${link_target} /sys/bus/pci/devices/${PCI_ADDR}"
77
78         sudo ip link set ${NETDEV} netns ${DCR_CPIDS[dut1]} || {
79             die "Moving interface to ${DCR_CPIDS[dut1]} namespace failed!"
80         }
81         docker exec "${DCR_UUIDS[dut1]}" ${cmd} ||  {
82             die "Linking PCI address in container failed!"
83         }
84     done
85 }
86
87
88 function bind_interfaces_to_driver () {
89
90     # Bind network interface specified by parameter to driver specified by
91     # parameter.
92     #
93     # Variables read:
94     # - ADDR - PCI address of network interface.
95     # - DRIVER - Kernel driver.
96
97     set -exuo pipefail
98
99     pci_path="/sys/bus/pci/devices/${ADDR}"
100     drv_path="/sys/bus/pci/drivers/${DRIVER}"
101     if [ -d "${pci_path}/driver" ]; then
102         echo ${ADDR} | sudo tee ${pci_path}/driver/unbind || {
103             die "Failed to unbind interface ${ADDR}!"
104         }
105     fi
106     echo ${ADDR} | sudo tee ${drv_path}/bind || {
107         die "Failed to bind interface ${ADDR}!"
108     }
109 }
110
111
112 function clean_environment () {
113
114     # Cleanup environment by removing topology containers and shared volumes
115     # and binding interfaces back to original driver.
116     #
117     # Variables read:
118     # - DCR_UUIDS - Docker Container UUIDs.
119     # - DUT1_PCIDEVS - List of PCI addresses of devices of DUT1 container.
120     # - TG_PCIDEVS - List of PCI addresses of devices of TG container.
121     # Variables set:
122     # - ADDR - PCI address of network interface.
123     # - DRIVER - Kernel driver.
124
125     set -exuo pipefail
126
127     # Kill docker containers.
128     docker rm --force "${DCR_UUIDS[@]}" || die "Cleanup containers failed!"
129
130     # Check if there are some leftover containers and remove all. Command will
131     # not fail in case there are no containers to remove.
132     docker rm --force $(docker ps -q --filter name=${DCR_UUIDS[dut1]}) || {
133         warn "Failed to remove hanged containers or nothing to remove!"
134     }
135
136     # Rebind interfaces back to kernel drivers.
137     for ADDR in ${TG_PCIDEVS[@]}; do
138         DRIVER="${TG_DRIVERS[0]}"
139         bind_interfaces_to_driver || die
140     done
141     for ADDR in ${DUT1_PCIDEVS[@]}; do
142         DRIVER="${DUT1_DRIVERS[0]}"
143         bind_interfaces_to_driver || die
144     done
145 }
146
147
148 function clean_environment_on_exit () {
149
150     # Cleanup environment by removing topology containers and binding
151     # interfaces back to original driver only if exit code is not 0.
152     # This function acts as workaround as 'set -eu' does not trigger ERR trap.
153
154     set -exuo pipefail
155
156     if [ $? -ne 0 ]; then
157         clean_environment || die
158     fi
159 }
160
161
162 function deactivate_wrapper () {
163
164     # Acts as wrapper for deactivate docker topology.
165     #
166     # Variables read:
167     # - ${@} - CSIT environment variables.
168
169     set -exuo pipefail
170
171     enter_mutex || die
172     read_env_variables "${@}" || die
173     clean_environment || die
174     exit_mutex || die
175 }
176
177
178 function die () {
179
180     # Print the message to standard error end exit with error code specified
181     # by the second argument.
182     #
183     # Duplicate of common.sh function, as this file is also used standalone.
184     #
185     # Hardcoded values:
186     # - The default error message.
187     # Arguments:
188     # - ${1} - The whole error message, be sure to quote. Optional
189     # - ${2} - the code to exit with, default: 1.
190
191     set -x
192     set +eu
193     warn "${1:-Unspecified run-time error occurred!}"
194     exit "${2:-1}"
195 }
196
197
198 function enter_mutex () {
199
200     # Enter mutual exclusion for protecting execution from starvation and
201     # deadlock.
202
203     set -exuo pipefail
204
205     mutex_timeout=3600
206     mutex_file="/tmp/mutex_file"
207
208     # Create mutex.
209     exec {lock_fd}>${mutex_file} || {
210         die "Mutex enter failed!"
211     }
212     flock --timeout "${mutex_timeout}" "${lock_fd}" || {
213         die "Calling flock() failed!"
214     }
215     # ----------------------
216     # Enter mutex succeeded.
217     warn "Mutex enter succeeded for PID $$."
218 }
219
220
221 function exit_mutex () {
222
223     # Exit mutual exclusion.
224
225     set -exuo pipefail
226
227     # ---------------------
228     # Remove mutex so we are not blocking others anymore.
229     flock -u "${lock_fd}" || {
230         die "Mutex destroy failed!"
231     }
232     warn "Mutex leave succeeded for PID $$."
233 }
234
235
236 function get_available_interfaces () {
237
238     # Find and get available Virtual functions.
239     #
240     # Arguments:
241     # - ${1} - Nodeness, as set by common.sh get_test_code.
242     # - ${2} - Flavor, as set by common.sh get_test_code.
243     # Variables set:
244     # - DUT1_NETDEVS - List of network devices allocated to DUT1 container.
245     # - DUT1_PCIDEVS - List of PCI addresses allocated to DUT1 container.
246     # - DUT1_NETMACS - List of MAC addresses allocated to DUT1 container.
247     # - DUT1_DRIVERS - List of interface drivers to DUT1 container.
248     # - TG_NETDEVS - List of network devices allocated to TG container.
249     # - TG_PCIDEVS - List of PCI addresses allocated to TG container.
250     # - TG_NETMACS - List of MAC addresses allocated to TG container.
251     # - TG_DRIVERS - List of interface drivers to TG container.
252
253     set -exuo pipefail
254
255     # Following code is specifing VFs ID based on nodeness and flavor.
256     # As there is great variability in hardware configuration outside LF,
257     # from bootstrap architecure point of view these are considered as flavors.
258     # Anyone can override flavor for its own machine and add condition here.
259     # See http://pci-ids.ucw.cz/v2.2/pci.ids for more info.
260     case_text="${1}_${2}"
261     case "${case_text}" in
262         "1n_skx")
263             # Add Intel Corporation XL710/X710 Virtual Function to the
264             # whitelist.
265             pci_id="0x154c"
266             tg_netdev=(enp24)
267             dut1_netdev=(enp59)
268             ;;
269        "1n_tx2")
270             # Add Intel Corporation XL710/X710 Virtual Function to the
271             # whitelist.
272             pci_id="0x154c"
273             tg_netdev=(enp5s2 enp5s3 enp5s4 enp5s5
274                        enp5s6 enp5s7 enp5s8 enp5s9)
275             tg_netdev+=(enp5s10 enp5s11 enp5s12 enp5s13
276                         enp5s14 enp5s15 enp5s16 enp5s17)
277             dut1_netdev=(enp145s2 enp145s3 enp145s4 enp145s5
278                          enp145s6 enp145s7 enp145s8 enp145s9)
279             dut1_netdev+=(enp145s10 enp145s11 enp145s12 enp145s13
280                           enp145s14 enp145s15 enp145s16 enp145s17)
281             ;;
282        "1n_vbox")
283             # Add Intel Corporation 82545EM Gigabit Ethernet Controller to the
284             # whitelist.
285             pci_id="0x100f"
286             tg_netdev=(enp0s8 enp0s9)
287             dut1_netdev=(enp0s16 enp0s17)
288             ;;
289         *)
290             die "Unknown specification: ${case_text}!"
291     esac
292
293     device_count=2
294
295     # TG side of connections.
296     TG_NETDEVS=()
297     TG_PCIDEVS=()
298     TG_NETMACS=()
299     TG_DRIVERS=()
300     TG_VLANS=()
301     # DUT1 side of connections.
302     DUT1_NETDEVS=()
303     DUT1_PCIDEVS=()
304     DUT1_NETMACS=()
305     DUT1_DRIVERS=()
306     DUT1_VLANS=()
307
308     # Find the first ${device_count} number of available TG Linux network
309     # VF device names. Only allowed VF PCI IDs are filtered.
310     for netdev in ${tg_netdev[@]}
311     do
312         for netdev_path in $(grep -l "${pci_id}" \
313                              /sys/class/net/${netdev}*/device/device \
314                              2> /dev/null)
315         do
316             if [[ ${#TG_NETDEVS[@]} -lt ${device_count} ]]; then
317                 tg_netdev_name=$(dirname ${netdev_path})
318                 tg_netdev_name=$(dirname ${tg_netdev_name})
319                 TG_NETDEVS+=($(basename ${tg_netdev_name}))
320             else
321                 break
322             fi
323         done
324         if [[ ${#TG_NETDEVS[@]} -eq ${device_count} ]]; then
325             break
326         fi
327     done
328
329     i=0
330     for netdev in "${TG_NETDEVS[@]}"; do
331         # Find the index of selected tg netdev among tg_netdevs
332         # e.g. enp8s5f7 is a vf of netdev enp8s5 with index 11
333         # and the corresponding dut1 netdev is enp133s13.
334         while [[ "${netdev}" != "${tg_netdev[$i]}"* ]]; do
335             ((i++))
336         done
337         # Rename tg netdev to dut1 netdev
338         # e.g. enp8s5f7 -> enp133s13f7
339         DUT1_NETDEVS+=(${netdev/${tg_netdev[$i]}/${dut1_netdev[$i]}})
340         # Don't need to reset i, all netdevs are sorted.
341     done
342
343     for NETDEV in "${TG_NETDEVS[@]}"; do
344         get_pci_addr
345         get_mac_addr
346         get_krn_driver
347         get_vlan_filter
348         TG_PCIDEVS+=(${PCI_ADDR})
349         TG_NETMACS+=(${MAC_ADDR})
350         TG_DRIVERS+=(${KRN_DRIVER})
351         TG_VLANS+=(${VLAN_ID})
352     done
353     for NETDEV in "${DUT1_NETDEVS[@]}"; do
354         get_pci_addr
355         get_mac_addr
356         get_krn_driver
357         get_vlan_filter
358         DUT1_PCIDEVS+=(${PCI_ADDR})
359         DUT1_NETMACS+=(${MAC_ADDR})
360         DUT1_DRIVERS+=(${KRN_DRIVER})
361         DUT1_VLANS+=(${VLAN_ID})
362     done
363
364     # We need at least two interfaces for TG/DUT1 for building topology.
365     if [ "${#TG_NETDEVS[@]}" -ne 2 ] || [ "${#DUT1_NETDEVS[@]}" -ne 2 ]; then
366         die "Not enough linux network interfaces found!"
367     fi
368     if [ "${#TG_PCIDEVS[@]}" -ne 2 ] || [ "${#DUT1_PCIDEVS[@]}" -ne 2 ]; then
369         die "Not enough pci interfaces found!"
370     fi
371 }
372
373
374 function get_krn_driver () {
375
376     # Get kernel driver from linux network device name.
377     #
378     # Variables read:
379     # - PCI_ADDR - PCI address of network device.
380     # Variables set:
381     # - KRN_DRIVER - Kernel driver of network device.
382
383     set -exuo pipefail
384
385     pci_path="/sys/bus/pci/devices/${PCI_ADDR}"
386     KRN_DRIVER="$(basename $(readlink -f ${pci_path}/driver))" || {
387         die "Failed to get kernel driver of PCI interface!"
388     }
389 }
390
391
392 function get_mac_addr () {
393
394     # Get MAC address from linux network device name.
395     #
396     # Variables read:
397     # - NETDEV - Linux network device name.
398     # Variables set:
399     # - MAC_ADDR - MAC address of network device.
400
401     set -exuo pipefail
402
403     if [ -d /sys/class/net/${NETDEV}/device ]; then
404         MAC_ADDR="$(</sys/class/net/${NETDEV}/address)" || {
405             die "Failed to get MAC address of linux network interface!"
406         }
407     fi
408 }
409
410
411 function get_pci_addr () {
412
413     # Get PCI address in <domain>:<bus:<device>.<func> format from linux network
414     # device name.
415     #
416     # Variables read:
417     # - NETDEV - Linux network device name.
418     # Variables set:
419     # - PCI_ADDR - PCI address of network device.
420
421     set -exuo pipefail
422
423     if [ -d /sys/class/net/${NETDEV}/device ]; then
424         PCI_ADDR=$(basename $(readlink /sys/class/net/${NETDEV}/device)) || {
425             die "Failed to get PCI address of linux network interface!"
426         }
427     fi
428     if [ ! -d /sys/bus/pci/devices/${PCI_ADDR} ]; then
429         die "PCI device ${NETDEV} doesn't exist!"
430     fi
431 }
432
433
434 function get_vlan_filter () {
435
436     # Get VLAN stripping filter from PF searched by mac adress.
437     #
438     # Variables read:
439     # - MAC_ADDR - MAC address of VF.
440     # Variables set:
441     # - VLAN_ID - VLAN ids.
442
443     set -exuo pipefail
444
445     # Sed regular expression pattern.
446     exp="s/^.*vlan ([[:digit:]]+).*$/\1/"
447     VLAN_ID=$(ip link | grep vlan | grep ${MAC_ADDR} | sed -re "${exp}") || true
448     VLAN_ID="${VLAN_ID:-0}"
449 }
450
451
452 function installed () {
453
454     # Check if the given utility is installed. Fail if not installed.
455     #
456     # Duplicate of common.sh function, as this file is also used standalone.
457     #
458     # Arguments:
459     # - ${1} - Utility to check.
460     # Returns:
461     # - 0 - If command is installed.
462     # - 1 - If command is not installed.
463
464     set -exuo pipefail
465
466     command -v "${1}"
467 }
468
469
470 function print_env_variables () {
471
472     # Get environment variables prefixed by CSIT_.
473
474     set -exuo pipefail
475
476     env | grep CSIT_ || true
477 }
478
479
480 function read_env_variables () {
481
482     # Read environment variables from parameters.
483     #
484     # Arguments:
485     # - ${@} - Variables passed as an argument.
486     # Variables read, set or exported: Multiple,
487     # see the code for the current list.
488     # TODO: Do we need to list them and their meanings?
489
490     set -exuo pipefail
491
492     for param in "$@"; do
493         export "${param}"
494     done
495     declare -gA DCR_UUIDS
496     DCR_UUIDS+=([tg]="${CSIT_TG_UUID}")
497     DCR_UUIDS+=([dut1]="${CSIT_DUT1_UUID}")
498     TG_PCIDEVS=("${CSIT_TG_INTERFACES_PORT1_PCI}")
499     TG_DRIVERS=("${CSIT_TG_INTERFACES_PORT1_DRV}")
500     TG_VLANS+=("${CSIT_TG_INTERFACES_PORT1_VLAN}")
501     TG_PCIDEVS+=("${CSIT_TG_INTERFACES_PORT2_PCI}")
502     TG_DRIVERS+=("${CSIT_TG_INTERFACES_PORT2_DRV}")
503     TG_VLANS+=("${CSIT_TG_INTERFACES_PORT2_VLAN}")
504     DUT1_PCIDEVS=("${CSIT_DUT1_INTERFACES_PORT1_PCI}")
505     DUT1_DRIVERS=("${CSIT_DUT1_INTERFACES_PORT1_DRV}")
506     DUT1_VLANS+=("${CSIT_DUT1_INTERFACES_PORT1_VLAN}")
507     DUT1_PCIDEVS+=("${CSIT_DUT1_INTERFACES_PORT2_PCI}")
508     DUT1_DRIVERS+=("${CSIT_DUT1_INTERFACES_PORT2_DRV}")
509     DUT1_VLANS+=("${CSIT_DUT1_INTERFACES_PORT2_VLAN}")
510 }
511
512
513 function set_env_variables () {
514
515     # Set environment variables.
516     #
517     # Variables read:
518     # - DCR_UUIDS - Docker Container UUIDs.
519     # - DCR_PORTS - Docker Container's SSH ports.
520     # - DUT1_NETMACS - List of network devices MAC addresses of DUT1 container.
521     # - DUT1_PCIDEVS - List of PCI addresses of devices of DUT1 container.
522     # - DUT1_DRIVERS - List of interface drivers to DUT1 container.
523     # - TG_NETMACS - List of network devices MAC addresses of TG container.
524     # - TG_PCIDEVS - List of PCI addresses of devices of TG container.
525     # - TG_DRIVERS - List of interface drivers to TG container.
526     # Variables set: TODO.
527
528     set -exuo pipefail
529
530     set -a
531     CSIT_TG_HOST="$(hostname --all-ip-addresses | awk '{print $1}')" || {
532         die "Reading hostname IP address failed!"
533     }
534     CSIT_TG_PORT="${DCR_PORTS[tg]#*:}"
535     CSIT_TG_UUID="${DCR_UUIDS[tg]}"
536     CSIT_TG_ARCH="$(uname -i)" || {
537         die "Reading machine architecture failed!"
538     }
539     CSIT_DUT1_HOST="$(hostname --all-ip-addresses | awk '{print $1}')" || {
540         die "Reading hostname IP address failed!"
541     }
542     CSIT_DUT1_PORT="${DCR_PORTS[dut1]#*:}"
543     CSIT_DUT1_UUID="${DCR_UUIDS[dut1]}"
544     CSIT_DUT1_ARCH="$(uname -i)" || {
545         die "Reading machine architecture failed!"
546     }
547     CSIT_TG_INTERFACES_PORT1_MAC="${TG_NETMACS[0]}"
548     CSIT_TG_INTERFACES_PORT1_PCI="${TG_PCIDEVS[0]}"
549     CSIT_TG_INTERFACES_PORT1_DRV="${TG_DRIVERS[0]}"
550     CSIT_TG_INTERFACES_PORT1_VLAN="${TG_VLANS[0]}"
551     CSIT_TG_INTERFACES_PORT2_MAC="${TG_NETMACS[1]}"
552     CSIT_TG_INTERFACES_PORT2_PCI="${TG_PCIDEVS[1]}"
553     CSIT_TG_INTERFACES_PORT2_DRV="${TG_DRIVERS[1]}"
554     CSIT_TG_INTERFACES_PORT2_VLAN="${TG_VLANS[1]}"
555     CSIT_DUT1_INTERFACES_PORT1_MAC="${DUT1_NETMACS[0]}"
556     CSIT_DUT1_INTERFACES_PORT1_PCI="${DUT1_PCIDEVS[0]}"
557     CSIT_DUT1_INTERFACES_PORT1_DRV="${DUT1_DRIVERS[0]}"
558     CSIT_DUT1_INTERFACES_PORT1_VLAN="${DUT1_VLANS[0]}"
559     CSIT_DUT1_INTERFACES_PORT2_MAC="${DUT1_NETMACS[1]}"
560     CSIT_DUT1_INTERFACES_PORT2_PCI="${DUT1_PCIDEVS[1]}"
561     CSIT_DUT1_INTERFACES_PORT2_DRV="${DUT1_DRIVERS[1]}"
562     CSIT_DUT1_INTERFACES_PORT2_VLAN="${DUT1_VLANS[1]}"
563     set +a
564 }
565
566
567 function start_topology_containers () {
568
569     # Starts csit-sut-dcr docker containers for TG/DUT1.
570     #
571     # Variables read:
572     # - CSIT_DIR - Path to existing root of local CSIT git repository.
573     # Variables set:
574     # - DCR_UUIDS - Docker Container UUIDs.
575     # - DCR_PORTS - Docker Container SSH TCP ports.
576     # - DCR_CPIDS - Docker Container PIDs (namespaces).
577
578     set -exuo pipefail
579
580     if ! installed docker; then
581         die "Docker not present. Please install before continue!"
582     fi
583
584     # If the IMAGE is not already loaded then docker run will pull the IMAGE,
585     # and all image dependencies, before it starts the container.
586     dcr_image="${1}"
587     # Run the container in the background and print the new container ID.
588     dcr_stc_params="--detach=true "
589     # Give extended privileges to this container. A "privileged" container is
590     # given access to all devices and able to run nested containers.
591     dcr_stc_params+="--privileged "
592     # Publish all exposed ports to random ports on the host interfaces.
593     dcr_stc_params+="--publish-all "
594     # Automatically remove the container when it exits.
595     dcr_stc_params+="--rm "
596     # Size of /dev/shm.
597     dcr_stc_params+="--shm-size 2G "
598     # Override access to PCI bus by attaching a filesystem mount to the
599     # container.
600     dcr_stc_params+="--mount type=tmpfs,destination=/sys/bus/pci/devices "
601     # Mount vfio to be able to bind to see bound interfaces. We cannot use
602     # --device=/dev/vfio as this does not see newly bound interfaces.
603     dcr_stc_params+="--volume /dev/vfio:/dev/vfio "
604     # Mount docker.sock to be able to use docker deamon of the host.
605     dcr_stc_params+="--volume /var/run/docker.sock:/var/run/docker.sock "
606     # Mount /opt/boot/ where VM kernel and initrd are located.
607     dcr_stc_params+="--volume /opt/boot/:/opt/boot/ "
608     # Mount host hugepages for VMs.
609     dcr_stc_params+="--volume /dev/hugepages/:/dev/hugepages/ "
610     # Disable IPv6.
611     dcr_stc_params+="--sysctl net.ipv6.conf.all.disable_ipv6=1 "
612     dcr_stc_params+="--sysctl net.ipv6.conf.default.disable_ipv6=1 "
613
614     # Docker Container UUIDs.
615     declare -gA DCR_UUIDS
616     # Docker Container SSH TCP ports.
617     declare -gA DCR_PORTS
618     # Docker Container PIDs (namespaces).
619     declare -gA DCR_CPIDS
620
621     # Run TG and DUT1. As initial version we do support only 2-node.
622     params=(${dcr_stc_params} --name csit-tg-$(uuidgen) ${dcr_image})
623     DCR_UUIDS+=([tg]=$(docker run "${params[@]}")) || {
624         die "Failed to start TG docker container!"
625     }
626     params=(${dcr_stc_params} --name csit-dut1-$(uuidgen) ${dcr_image})
627     DCR_UUIDS+=([dut1]=$(docker run "${params[@]}")) || {
628         die "Failed to start DUT1 docker container!"
629     }
630
631     trap 'clean_environment_on_exit' EXIT || {
632         die "Trap attempt failed, please cleanup manually. Aborting!"
633     }
634
635     # Get Containers TCP ports.
636     params=(${DCR_UUIDS[tg]})
637     DCR_PORTS+=([tg]=$(docker port "${params[@]}")) || {
638         die "Failed to get port of TG docker container!"
639     }
640     params=(${DCR_UUIDS[dut1]})
641     DCR_PORTS+=([dut1]=$(docker port "${params[@]}")) || {
642         die "Failed to get port of DUT1 docker container!"
643     }
644
645     # Get Containers PIDs.
646     params=(--format="{{ .State.Pid }}" ${DCR_UUIDS[tg]})
647     DCR_CPIDS+=([tg]=$(docker inspect "${params[@]}")) || {
648         die "Failed to get PID of TG docker container!"
649     }
650     params=(--format="{{ .State.Pid }}" ${DCR_UUIDS[dut1]})
651     DCR_CPIDS+=([dut1]=$(docker inspect "${params[@]}")) || {
652         die "Failed to get PID of DUT1 docker container!"
653     }
654 }
655
656 function warn () {
657     # Print the message to standard error.
658     #
659     # Duplicate of common.sh function, as this file is also used standalone.
660     #
661     # Arguments:
662     # - ${@} - The text of the message.
663
664     set -exuo pipefail
665
666     echo "$@" >&2
667 }