-
Notifications
You must be signed in to change notification settings - Fork 13
/
common-bf.sh
144 lines (120 loc) · 2.95 KB
/
common-bf.sh
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
function on_bf() {
__on_remote $BF_IP "$@"
}
function on_remote_bf() {
__on_remote $REMOTE_BF_IP "$@"
}
function on_bf_exec() {
__on_remote_exec $BF_IP "$@"
}
function on_remote_bf_exec() {
__on_remote_exec $REMOTE_BF_IP "$@"
}
function require_bf() {
if [ -z "$BF_IP" ]; then
fail "BF IP is not configured"
fi
log "BF $BF_IP"
on_bf true || fail "BF command failed"
print_remote_test_separator $BF_IP
on_bf "echo MLNX_OFED \`modinfo --field version mlx5_core\` | tee -a /dev/kmsg"
}
function require_remote_bf() {
if [ -z "$REMOTE_BF_IP" ]; then
fail "Remote BF IP is not configured"
fi
log "Remote BF $REMOTE_BF_IP"
on_remote_bf true || fail "Remote BF command failed"
}
function remote_bf_wrap() {
if is_bf_host; then
on_remote_bf "$@"
else
on_remote "$@"
fi
}
function remote_bf_wrap_exec() {
if is_bf_host; then
on_remote_bf_exec "$@"
else
on_remote_exec "$@"
fi
}
function bf_wrap() {
if is_bf_host; then
on_bf "$@"
else
eval "$@"
fi
}
function bf_wrap_exec() {
if is_bf_host; then
on_bf_exec "$@"
else
eval "$@"
fi
}
function __config_vf() {
local ns=$1
local vf=$2
local ip=$3 # optional
local mac=$4 # optional
local prefix=24
if [[ "$ip" == *":"* ]]; then
# ipv6
prefix=64
fi
ip netns add $ns
${mac:+ip link set $vf address $mac}
ip link set $vf netns $ns
${ip:+ip -netns $ns address replace dev $vf $ip/$prefix}
ip -netns $ns link set $vf up
}
function config_remote_bf_vf() {
local ns=$1
local vf=$2
local rep=$3
local ip=$4 # optional
local mac=$5 # optional
echo "[$ns] $vf (${mac:+$mac/}$ip) -> BF $rep"
on_remote_exec "__config_vf $ns $vf $ip $mac"
on_remote_bf_exec "__config_rep $rep"
}
function ovs-vsctl() {
if is_bf_host; then
on_bf command ovs-vsctl "$@"
else
command ovs-vsctl "$@"
fi
}
function ovs-ofctl() {
if is_bf_host; then
local cmd="$@"
# Note: Escape special character and remove any extra space after comma.
cmd=$(echo $cmd | sed -e 's/)/\\)/g' -e 's/(/\\(/g' -e 's/->/\\-\\>/g' -e 's/\]/\\]/g' -e 's/\[/\\[/g' -e 's/}/\\}/g' -e 's/{/\\{/g' -e 's/, /,/g')
on_bf command ovs-ofctl "$cmd"
else
command ovs-ofctl "$@"
fi
}
function ovs-appctl() {
if is_bf_host; then
on_bf command ovs-appctl "$@"
else
command ovs-appctl "$@"
fi
}
function __setup_common_bf() {
if ! is_bf_host && ! is_bf ; then
return
fi
BF_PCI=$(bf_wrap "basename \$(readlink /sys/class/net/${BF_NIC}/device)")
BF_PCI2=$(bf_wrap "basename \$(readlink /sys/class/net/${BF_NIC2}/device)")
bf_wrap """
source /etc/os-release
echo -e \"ARM ${ANSI_COLOR0}\${PRETTY_NAME}$NOCOLOR\"
uname -a
"""
echo "ARM NIC $BF_NIC PCI $BF_PCI"
}
__setup_common_bf