cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

tc_action_hw_stats.sh (2293B)


      1#!/bin/bash
      2# SPDX-License-Identifier: GPL-2.0
      3
      4lib_dir=$(dirname $0)/../../../net/forwarding
      5
      6ALL_TESTS="
      7	default_hw_stats_test
      8	immediate_hw_stats_test
      9	delayed_hw_stats_test
     10	disabled_hw_stats_test
     11"
     12NUM_NETIFS=2
     13
     14source $lib_dir/tc_common.sh
     15source $lib_dir/lib.sh
     16source $lib_dir/devlink_lib.sh
     17
     18h1_create()
     19{
     20	simple_if_init $h1 192.0.2.1/24
     21}
     22
     23h1_destroy()
     24{
     25	simple_if_fini $h1 192.0.2.1/24
     26}
     27
     28switch_create()
     29{
     30	simple_if_init $swp1 192.0.2.2/24
     31	tc qdisc add dev $swp1 clsact
     32}
     33
     34switch_destroy()
     35{
     36	tc qdisc del dev $swp1 clsact
     37	simple_if_fini $swp1 192.0.2.2/24
     38}
     39
     40hw_stats_test()
     41{
     42	RET=0
     43
     44	local name=$1
     45	local action_hw_stats=$2
     46	local occ_delta=$3
     47	local expected_packet_count=$4
     48
     49	local orig_occ=$(devlink_resource_get "counters" "flow" | jq '.["occ"]')
     50
     51	tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
     52		skip_sw dst_ip 192.0.2.2 action drop $action_hw_stats
     53	check_err $? "Failed to add rule with $name hw_stats"
     54
     55	local new_occ=$(devlink_resource_get "counters" "flow" | jq '.["occ"]')
     56	local expected_occ=$((orig_occ + occ_delta))
     57	[ "$new_occ" == "$expected_occ" ]
     58	check_err $? "Expected occupancy of $expected_occ, got $new_occ"
     59
     60	$MZ $h1 -c 1 -p 64 -a $h1mac -b $swp1mac -A 192.0.2.1 -B 192.0.2.2 \
     61		-t ip -q
     62
     63	tc_check_packets "dev $swp1 ingress" 101 $expected_packet_count
     64	check_err $? "Did not match incoming packet"
     65
     66	tc filter del dev $swp1 ingress protocol ip pref 1 handle 101 flower
     67
     68	log_test "$name hw_stats"
     69}
     70
     71default_hw_stats_test()
     72{
     73	hw_stats_test "default" "" 2 1
     74}
     75
     76immediate_hw_stats_test()
     77{
     78	hw_stats_test "immediate" "hw_stats immediate" 2 1
     79}
     80
     81delayed_hw_stats_test()
     82{
     83	RET=0
     84
     85	tc filter add dev $swp1 ingress protocol ip pref 1 handle 101 flower \
     86		skip_sw dst_ip 192.0.2.2 action drop hw_stats delayed
     87	check_fail $? "Unexpected success in adding rule with delayed hw_stats"
     88
     89	log_test "delayed hw_stats"
     90}
     91
     92disabled_hw_stats_test()
     93{
     94	hw_stats_test "disabled" "hw_stats disabled" 0 0
     95}
     96
     97setup_prepare()
     98{
     99	h1=${NETIFS[p1]}
    100	swp1=${NETIFS[p2]}
    101
    102	h1mac=$(mac_get $h1)
    103	swp1mac=$(mac_get $swp1)
    104
    105	vrf_prepare
    106
    107	h1_create
    108	switch_create
    109}
    110
    111cleanup()
    112{
    113	pre_cleanup
    114
    115	switch_destroy
    116	h1_destroy
    117
    118	vrf_cleanup
    119}
    120
    121check_tc_action_hw_stats_support
    122
    123trap cleanup EXIT
    124
    125setup_prepare
    126setup_wait
    127
    128tests_run
    129
    130exit $EXIT_STATUS