github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/metrics/network/lib/network-common.bash (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2018 Intel Corporation 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 7 # Description: This file contains functions that are shared among the networking 8 # tests that are using nuttcp and iperf3 9 10 SCRIPT_PATH=$(dirname "$(readlink -f "$0")") 11 source "${SCRIPT_PATH}/../lib/common.bash" 12 13 # This function will launch a container in detached mode and 14 # it will return the IP address, the role of this container is as a server. 15 # Arguments: 16 # Docker image. 17 # Command[s] to be executed. 18 # Extra argument for container execution. 19 function start_server() 20 { 21 local image="$1" 22 local cmd="$2" 23 local extra_args="$3" 24 25 # Launch container 26 instance_id="$(docker run $extra_args -d --runtime "$RUNTIME" \ 27 "$image" sh -c "$cmd")" 28 29 # Get IP Address 30 server_address=$(docker inspect --format "{{.NetworkSettings.IPAddress}}" $instance_id) 31 32 echo "$server_address" 33 } 34 35 # This function will launch a container and it will execute a determined 36 # workload, this workload is received as an argument and this function will 37 # return the output/result of the workload. The role of this container is as a client. 38 # Arguments: 39 # Docker image 40 # Command[s] to be executed 41 # Extra argument for container execution 42 function start_client() 43 { 44 local image="$1" 45 local cmd="$2" 46 local extra_args="$3" 47 48 # Execute client/workload and return result output 49 output="$(docker run $extra_args --runtime "$RUNTIME" \ 50 "$image" sh -c "$cmd")" 51 52 echo "$output" 53 }