summaryrefslogtreecommitdiff
path: root/automated/linux/ethernet/ethernet.sh
blob: 67f7e28bad296ca3ed0a0fc6d514bd13e1a56199 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh

# shellcheck disable=SC1091
. ../../lib/sh-test-lib

OUTPUT="$(pwd)/output"
RESULT_FILE="${OUTPUT}/result.txt"
export RESULT_FILE

# Default ethernet interface
INTERFACE="eth0"

usage() {
    echo "Usage: $0 [-i <ethernet-interface> -s <true|false>]" 1>&2
    exit 1
}

while getopts "s:i:" o; do
  case "$o" in
    s) SKIP_INSTALL="${OPTARG}" ;;
    # Ethernet interface
    i) INTERFACE="${OPTARG}" ;;
    *) usage ;;
  esac
done

# Test run.
! check_root && error_msg "This script must be run as root"
[ -d "${OUTPUT}" ] && mv "${OUTPUT}" "${OUTPUT}_$(date +%Y%m%d%H%M%S)"
mkdir -p "${OUTPUT}"

pkgs="net-tools"
install_deps "${pkgs}" "${SKIP_INSTALL}"

# Print all network interface status
ip addr
# Print given network interface status
ip addr show "${INTERFACE}"

# Get IP address of a given interface
IP_ADDR=$(ip addr show "${INTERFACE}" | grep -a2 "state UP" | tail -1 | awk '{print $2}' | cut -f1 -d'/')

[ -n "${IP_ADDR}" ]
exit_on_fail "ethernet-ping-state-UP" "ethernet-ping-route"

# Get default Route IP address of a given interface
ROUTE_ADDR=$(ip route list  | grep default | awk '{print $3}' | head -1)

# Run the test
run_test_case "ping -c 5 ${ROUTE_ADDR}" "ethernet-ping-route"