__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0
#
# Test devlink-trap policer functionality over mlxsw.

# +---------------------------------+
# | H1 (vrf)                        |
# |    + $h1                        |
# |    | 192.0.2.1/24               |
# |    |                            |
# |    |  default via 192.0.2.2     |
# +----|----------------------------+
#      |
# +----|----------------------------------------------------------------------+
# | SW |                                                                      |
# |    + $rp1                                                                 |
# |        192.0.2.2/24                                                       |
# |                                                                           |
# |        198.51.100.2/24                                                    |
# |    + $rp2                                                                 |
# |    |                                                                      |
# +----|----------------------------------------------------------------------+
#      |
# +----|----------------------------+
# |    |  default via 198.51.100.2  |
# |    |                            |
# |    | 198.51.100.1/24            |
# |    + $h2                        |
# | H2 (vrf)                        |
# +---------------------------------+

lib_dir=$(dirname $0)/../../../net/forwarding

ALL_TESTS="
	rate_limits_test
	burst_limits_test
	rate_test
	burst_test
"
NUM_NETIFS=4
source $lib_dir/tc_common.sh
source $lib_dir/lib.sh
source $lib_dir/devlink_lib.sh

h1_create()
{
	simple_if_init $h1 192.0.2.1/24
	defer simple_if_fini $h1 192.0.2.1/24

	mtu_set $h1 10000
	defer mtu_restore $h1

	ip -4 route add default vrf v$h1 nexthop via 192.0.2.2
	defer ip -4 route del default vrf v$h1 nexthop via 192.0.2.2
}

h2_create()
{
	simple_if_init $h2 198.51.100.1/24
	defer simple_if_fini $h2 198.51.100.1/24

	mtu_set $h2 10000
	defer mtu_restore $h2

	ip -4 route add default vrf v$h2 nexthop via 198.51.100.2
	defer ip -4 route del default vrf v$h2 nexthop via 198.51.100.2
}

router_create()
{
	ip link set dev $rp1 up
	defer ip link set dev $rp1 down

	ip link set dev $rp2 up
	defer ip link set dev $rp2 down

	__addr_add_del $rp1 add 192.0.2.2/24
	defer __addr_add_del $rp1 del 192.0.2.2/24

	__addr_add_del $rp2 add 198.51.100.2/24
	defer __addr_add_del $rp2 del 198.51.100.2/24

	mtu_set $rp1 10000
	defer mtu_restore $rp1

	mtu_set $rp2 10000
	defer mtu_restore $rp2

	ip -4 route add blackhole 198.51.100.100
	defer ip -4 route del blackhole 198.51.100.100

	devlink trap set $DEVLINK_DEV trap blackhole_route action trap
	defer devlink trap set $DEVLINK_DEV trap blackhole_route action drop
}

setup_prepare()
{
	h1=${NETIFS[p1]}
	rp1=${NETIFS[p2]}

	rp2=${NETIFS[p3]}
	h2=${NETIFS[p4]}

	rp1_mac=$(mac_get $rp1)

	# Reload to ensure devlink-trap settings are back to default.
	defer devlink_reload

	vrf_prepare
	defer vrf_cleanup

	h1_create
	h2_create

	router_create
}

rate_limits_test()
{
	RET=0

	devlink trap policer set $DEVLINK_DEV policer 1 rate 0 &> /dev/null
	check_fail $? "Policer rate was changed to rate lower than limit"
	devlink trap policer set $DEVLINK_DEV policer 1 \
		rate 2000000001 &> /dev/null
	check_fail $? "Policer rate was changed to rate higher than limit"

	devlink trap policer set $DEVLINK_DEV policer 1 rate 1
	check_err $? "Failed to set policer rate to minimum"
	devlink trap policer set $DEVLINK_DEV policer 1 rate 2000000000
	check_err $? "Failed to set policer rate to maximum"

	log_test "Trap policer rate limits"
}

burst_limits_test()
{
	RET=0

	devlink trap policer set $DEVLINK_DEV policer 1 burst 0 &> /dev/null
	check_fail $? "Policer burst size was changed to 0"
	devlink trap policer set $DEVLINK_DEV policer 1 burst 17 &> /dev/null
	check_fail $? "Policer burst size was changed to burst size that is not power of 2"
	devlink trap policer set $DEVLINK_DEV policer 1 burst 8 &> /dev/null
	check_fail $? "Policer burst size was changed to burst size lower than limit"
	devlink trap policer set $DEVLINK_DEV policer 1 \
		burst $((2**25)) &> /dev/null
	check_fail $? "Policer burst size was changed to burst size higher than limit"

	devlink trap policer set $DEVLINK_DEV policer 1 burst 16
	check_err $? "Failed to set policer burst size to minimum"
	devlink trap policer set $DEVLINK_DEV policer 1 burst $((2**24))
	check_err $? "Failed to set policer burst size to maximum"

	log_test "Trap policer burst size limits"
}

trap_rate_get()
{
	local t0 t1

	t0=$(devlink_trap_rx_packets_get blackhole_route)
	sleep 10
	t1=$(devlink_trap_rx_packets_get blackhole_route)

	echo $(((t1 - t0) / 10))
}

policer_drop_rate_get()
{
	local id=$1; shift
	local t0 t1

	t0=$(devlink_trap_policer_rx_dropped_get $id)
	sleep 10
	t1=$(devlink_trap_policer_rx_dropped_get $id)

	echo $(((t1 - t0) / 10))
}

__rate_test()
{
	local rate pct drop_rate
	local id=$1; shift

	RET=0

	devlink trap policer set $DEVLINK_DEV policer $id rate 1000 burst 512
	devlink trap group set $DEVLINK_DEV group l3_drops policer $id

	# Send packets at highest possible rate and make sure they are dropped
	# by the policer. Make sure measured received rate is about 1000 pps
	log_info "=== Tx rate: Highest, Policer rate: 1000 pps ==="

	defer_scope_push

	start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac
	defer stop_traffic $!

	sleep 5 # Take measurements when rate is stable

	rate=$(trap_rate_get)
	pct=$((100 * (rate - 1000) / 1000))
	((-10 <= pct && pct <= 10))
	check_err $? "Expected rate 1000 pps, got $rate pps, which is $pct% off. Required accuracy is +-10%"
	log_info "Expected rate 1000 pps, measured rate $rate pps"

	drop_rate=$(policer_drop_rate_get $id)
	(( drop_rate > 0 ))
	check_err $? "Expected non-zero policer drop rate, got 0"
	log_info "Measured policer drop rate of $drop_rate pps"

	defer_scope_pop

	# Send packets at a rate of 1000 pps and make sure they are not dropped
	# by the policer
	log_info "=== Tx rate: 1000 pps, Policer rate: 1000 pps ==="

	defer_scope_push

	start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac -d 1msec
	defer stop_traffic $!

	sleep 5 # Take measurements when rate is stable

	drop_rate=$(policer_drop_rate_get $id)
	(( drop_rate == 0 ))
	check_err $? "Expected zero policer drop rate, got a drop rate of $drop_rate pps"
	log_info "Measured policer drop rate of $drop_rate pps"

	defer_scope_pop

	# Unbind the policer and send packets at highest possible rate. Make
	# sure they are not dropped by the policer and that the measured
	# received rate is higher than 1000 pps
	log_info "=== Tx rate: Highest, Policer rate: No policer ==="

	devlink trap group set $DEVLINK_DEV group l3_drops nopolicer

	defer_scope_push

	start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac
	defer stop_traffic $!

	rate=$(trap_rate_get)
	(( rate > 1000 ))
	check_err $? "Expected rate higher than 1000 pps, got $rate pps"
	log_info "Measured rate $rate pps"

	drop_rate=$(policer_drop_rate_get $id)
	(( drop_rate == 0 ))
	check_err $? "Expected zero policer drop rate, got a drop rate of $drop_rate pps"
	log_info "Measured policer drop rate of $drop_rate pps"

	defer_scope_pop

	log_test "Trap policer rate"
}

rate_test()
{
	local last_policer=$(devlink -j -p trap policer show |
			     jq '[.[]["'$DEVLINK_DEV'"][].policer] | max')

	log_info "Running rate test for policer 1"
	__rate_test 1

	log_info "Running rate test for policer $((last_policer / 2))"
	__rate_test $((last_policer / 2))

	log_info "Running rate test for policer $last_policer"
	__rate_test $last_policer
}

__burst_test()
{
	local t0_rx t0_drop t1_rx t1_drop rx drop
	local id=$1; shift

	RET=0

	devlink trap policer set $DEVLINK_DEV policer $id rate 1000 burst 512
	devlink trap group set $DEVLINK_DEV group l3_drops policer $id

	# Send a burst of 16 packets and make sure that 16 are received
	# and that none are dropped by the policer
	log_info "=== Tx burst size: 16, Policer burst size: 512 ==="

	t0_rx=$(devlink_trap_rx_packets_get blackhole_route)
	t0_drop=$(devlink_trap_policer_rx_dropped_get $id)

	start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac -c 16

	t1_rx=$(devlink_trap_rx_packets_get blackhole_route)
	t1_drop=$(devlink_trap_policer_rx_dropped_get $id)

	rx=$((t1_rx - t0_rx))
	(( rx == 16 ))
	check_err $? "Expected burst size of 16 packets, got $rx packets"
	log_info "Expected burst size of 16 packets, measured burst size of $rx packets"

	drop=$((t1_drop - t0_drop))
	(( drop == 0 ))
	check_err $? "Expected zero policer drops, got $drop"
	log_info "Measured policer drops of $drop packets"

	# Unbind the policer and send a burst of 64 packets. Make sure that
	# 64 packets are received and that none are dropped by the policer
	log_info "=== Tx burst size: 64, Policer burst size: No policer ==="

	devlink trap group set $DEVLINK_DEV group l3_drops nopolicer

	t0_rx=$(devlink_trap_rx_packets_get blackhole_route)
	t0_drop=$(devlink_trap_policer_rx_dropped_get $id)

	start_traffic $h1 192.0.2.1 198.51.100.100 $rp1_mac -c 64

	t1_rx=$(devlink_trap_rx_packets_get blackhole_route)
	t1_drop=$(devlink_trap_policer_rx_dropped_get $id)

	rx=$((t1_rx - t0_rx))
	(( rx == 64 ))
	check_err $? "Expected burst size of 64 packets, got $rx packets"
	log_info "Expected burst size of 64 packets, measured burst size of $rx packets"

	drop=$((t1_drop - t0_drop))
	(( drop == 0 ))
	check_err $? "Expected zero policer drops, got $drop"
	log_info "Measured policer drops of $drop packets"

	log_test "Trap policer burst size"
}

burst_test()
{
	local last_policer=$(devlink -j -p trap policer show |
			     jq '[.[]["'$DEVLINK_DEV'"][].policer] | max')

	log_info "Running burst test for policer 1"
	__burst_test 1

	log_info "Running burst test for policer $((last_policer / 2))"
	__burst_test $((last_policer / 2))

	log_info "Running burst test for policer $last_policer"
	__burst_test $last_policer
}

trap cleanup EXIT

setup_prepare
setup_wait

tests_run

exit $EXIT_STATUS

Filemanager

Name Type Size Permission Actions
spectrum Folder 0755
spectrum-2 Folder 0755
blackhole_routes.sh File 4.96 KB 0755
devlink_linecard.sh File 7.5 KB 0755
devlink_trap.sh File 1.86 KB 0755
devlink_trap_acl_drops.sh File 2.4 KB 0755
devlink_trap_control.sh File 18.22 KB 0755
devlink_trap_l2_drops.sh File 12.87 KB 0755
devlink_trap_l3_drops.sh File 16.38 KB 0755
devlink_trap_l3_exceptions.sh File 13.64 KB 0755
devlink_trap_policer.sh File 9.75 KB 0755
devlink_trap_tunnel_ipip.sh File 5.24 KB 0755
devlink_trap_tunnel_ipip6.sh File 5.31 KB 0755
devlink_trap_tunnel_vxlan.sh File 8.84 KB 0755
devlink_trap_tunnel_vxlan_ipv6.sh File 9.32 KB 0755
egress_vid_classification.sh File 6.55 KB 0755
ethtool_lanes.sh File 4.02 KB 0755
extack.sh File 3.74 KB 0755
fib.sh File 5.43 KB 0755
fib_offload.sh File 9.93 KB 0755
hw_stats_l3.sh File 410 B 0755
ingress_rif_conf_1d.sh File 6.15 KB 0755
ingress_rif_conf_1q.sh File 6.23 KB 0755
ingress_rif_conf_vxlan.sh File 8.44 KB 0755
mirror_gre.sh File 3.78 KB 0755
mirror_gre_scale.sh File 5.43 KB 0644
mlxsw_lib.sh File 1.43 KB 0644
one_armed_router.sh File 6.82 KB 0755
pci_reset.sh File 1.27 KB 0755
port_range_occ.sh File 2.33 KB 0755
port_range_scale.sh File 1.51 KB 0644
port_scale.sh File 1.36 KB 0644
q_in_q_veto.sh File 8.06 KB 0755
qos_defprio.sh File 2.33 KB 0755
qos_dscp_bridge.sh File 4.14 KB 0755
qos_dscp_router.sh File 6.43 KB 0755
qos_ets_strict.sh File 9.09 KB 0755
qos_headroom.sh File 8.19 KB 0755
qos_lib.sh File 1.27 KB 0644
qos_max_descriptors.sh File 6.14 KB 0755
qos_mc_aware.sh File 9.54 KB 0755
qos_pfc.sh File 11.36 KB 0755
rif_bridge.sh File 4.12 KB 0755
rif_counter_scale.sh File 1.71 KB 0644
rif_lag.sh File 2.98 KB 0755
rif_lag_vlan.sh File 3.24 KB 0755
rif_mac_profile_scale.sh File 1.64 KB 0644
rif_mac_profiles.sh File 4.65 KB 0755
rif_mac_profiles_occ.sh File 2.87 KB 0755
router_bridge_lag.sh File 786 B 0755
router_scale.sh File 2.09 KB 0644
rtnetlink.sh File 26.93 KB 0755
sch_ets.sh File 2.3 KB 0755
sch_offload.sh File 5.25 KB 0755
sch_red_core.sh File 20.75 KB 0644
sch_red_ets.sh File 3.12 KB 0755
sch_red_prio.sh File 81 B 0755
sch_red_root.sh File 1.25 KB 0755
sch_tbf_ets.sh File 216 B 0755
sch_tbf_prio.sh File 217 B 0755
sch_tbf_root.sh File 217 B 0755
sharedbuffer.sh File 5.24 KB 0755
tc_action_hw_stats.sh File 2.24 KB 0755
tc_flower_scale.sh File 2.81 KB 0644
tc_police_occ.sh File 2.07 KB 0755
tc_police_scale.sh File 1.62 KB 0644
tc_restrictions.sh File 11.58 KB 0755
tc_sample.sh File 17.38 KB 0755
vxlan.sh File 30.19 KB 0755
vxlan_fdb_veto.sh File 3.11 KB 0755
vxlan_fdb_veto_ipv6.sh File 250 B 0755
vxlan_flooding.sh File 8.64 KB 0755
vxlan_ipv6.sh File 1.39 KB 0755
Filemanager