xref: /openbmc/linux/samples/bpf/lwt_len_hist.sh (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
1f74599f7SThomas Graf#!/bin/bash
2b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
3f74599f7SThomas Graf
4f74599f7SThomas GrafNS1=lwt_ns1
5f74599f7SThomas GrafVETH0=tst_lwt1a
6f74599f7SThomas GrafVETH1=tst_lwt1b
7e04946f5SDaniel T. LeeBPF_PROG=lwt_len_hist.bpf.o
8*27d7fdf0SRoss ZwislerTRACE_ROOT=/sys/kernel/tracing
9f74599f7SThomas Graf
10f74599f7SThomas Graffunction cleanup {
110afe0a99SDaniel T. Lee	# To reset saved histogram, remove pinned map
120afe0a99SDaniel T. Lee	rm /sys/fs/bpf/tc/globals/lwt_len_hist_map
13f74599f7SThomas Graf	ip route del 192.168.253.2/32 dev $VETH0 2> /dev/null
14f74599f7SThomas Graf	ip link del $VETH0 2> /dev/null
15f74599f7SThomas Graf	ip link del $VETH1 2> /dev/null
16f74599f7SThomas Graf	ip netns exec $NS1 killall netserver
17f74599f7SThomas Graf	ip netns delete $NS1 2> /dev/null
18f74599f7SThomas Graf}
19f74599f7SThomas Graf
20f74599f7SThomas Grafcleanup
21f74599f7SThomas Graf
22f74599f7SThomas Grafip netns add $NS1
23f74599f7SThomas Grafip link add $VETH0 type veth peer name $VETH1
24f74599f7SThomas Grafip link set dev $VETH0 up
25f74599f7SThomas Grafip addr add 192.168.253.1/24 dev $VETH0
26f74599f7SThomas Grafip link set $VETH1 netns $NS1
27f74599f7SThomas Grafip netns exec $NS1 ip link set dev $VETH1 up
28f74599f7SThomas Grafip netns exec $NS1 ip addr add 192.168.253.2/24 dev $VETH1
29f74599f7SThomas Grafip netns exec $NS1 netserver
30f74599f7SThomas Graf
31f74599f7SThomas Grafecho 1 > ${TRACE_ROOT}/tracing_on
32f74599f7SThomas Grafcp /dev/null ${TRACE_ROOT}/trace
33f20f064eSDaniel T. Leeip route add 192.168.253.2/32 encap bpf out obj $BPF_PROG section len_hist dev $VETH0
34f74599f7SThomas Grafnetperf -H 192.168.253.2 -t TCP_STREAM
35f74599f7SThomas Grafcat ${TRACE_ROOT}/trace | grep -v '^#'
36f74599f7SThomas Graf./lwt_len_hist
37f74599f7SThomas Grafcleanup
38f74599f7SThomas Grafecho 0 > ${TRACE_ROOT}/tracing_on
39f74599f7SThomas Graf
40f74599f7SThomas Grafexit 0
41