Commit 72642f41 authored by David S. Miller's avatar David S. Miller

Merge branch 'selftests-packets-per-second'

Simon Horman says:

====================
selftest: add tests for packet per second

Add self tests for the recently added packet per second rate limiting
feature of the TC policer action[1].

The forwarding selftest (patch 2/2) depends on iproute2 support
for packet per second rate limiting, which has been posted separately[2]

[1] [PATCH v3 net-next 0/3] net/sched: act_police: add support for packet-per-second policing
    https://lore.kernel.org/netdev/20210312140831.23346-1-simon.horman@netronome.com/

[2] [PATCH iproute2-next] police: add support for packet-per-second rate limiting
    https://lore.kernel.org/netdev/20210326125018.32091-1-simon.horman@netronome.com/
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents a7fd0e6d 53b61f29
...@@ -772,6 +772,15 @@ rate() ...@@ -772,6 +772,15 @@ rate()
echo $((8 * (t1 - t0) / interval)) echo $((8 * (t1 - t0) / interval))
} }
packets_rate()
{
local t0=$1; shift
local t1=$1; shift
local interval=$1; shift
echo $(((t1 - t0) / interval))
}
mac_get() mac_get()
{ {
local if_name=$1 local if_name=$1
......
...@@ -35,6 +35,8 @@ ALL_TESTS=" ...@@ -35,6 +35,8 @@ ALL_TESTS="
police_shared_test police_shared_test
police_rx_mirror_test police_rx_mirror_test
police_tx_mirror_test police_tx_mirror_test
police_pps_rx_test
police_pps_tx_test
" "
NUM_NETIFS=6 NUM_NETIFS=6
source tc_common.sh source tc_common.sh
...@@ -290,6 +292,60 @@ police_tx_mirror_test() ...@@ -290,6 +292,60 @@ police_tx_mirror_test()
police_mirror_common_test $rp2 egress "police tx and mirror" police_mirror_common_test $rp2 egress "police tx and mirror"
} }
police_pps_common_test()
{
local test_name=$1; shift
RET=0
# Rule to measure bandwidth on ingress of $h2
tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
dst_ip 198.51.100.1 ip_proto udp dst_port 54321 \
action drop
mausezahn $h1 -a own -b $(mac_get $rp1) -A 192.0.2.1 -B 198.51.100.1 \
-t udp sp=12345,dp=54321 -p 1000 -c 0 -q &
local t0=$(tc_rule_stats_get $h2 1 ingress .packets)
sleep 10
local t1=$(tc_rule_stats_get $h2 1 ingress .packets)
local er=$((2000))
local nr=$(packets_rate $t0 $t1 10)
local nr_pct=$((100 * (nr - er) / er))
((-10 <= nr_pct && nr_pct <= 10))
check_err $? "Expected rate $(humanize $er), got $(humanize $nr), which is $nr_pct% off. Required accuracy is +-10%."
log_test "$test_name"
{ kill %% && wait %%; } 2>/dev/null
tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower
}
police_pps_rx_test()
{
# Rule to police traffic destined to $h2 on ingress of $rp1
tc filter add dev $rp1 ingress protocol ip pref 1 handle 101 flower \
dst_ip 198.51.100.1 ip_proto udp dst_port 54321 \
action police pkts_rate 2000 pkts_burst 400 conform-exceed drop/ok
police_pps_common_test "police pps on rx"
tc filter del dev $rp1 ingress protocol ip pref 1 handle 101 flower
}
police_pps_tx_test()
{
# Rule to police traffic destined to $h2 on egress of $rp2
tc filter add dev $rp2 egress protocol ip pref 1 handle 101 flower \
dst_ip 198.51.100.1 ip_proto udp dst_port 54321 \
action police pkts_rate 2000 pkts_burst 400 conform-exceed drop/ok
police_pps_common_test "police pps on tx"
tc filter del dev $rp2 egress protocol ip pref 1 handle 101 flower
}
setup_prepare() setup_prepare()
{ {
h1=${NETIFS[p1]} h1=${NETIFS[p1]}
......
...@@ -764,5 +764,53 @@ ...@@ -764,5 +764,53 @@
"teardown": [ "teardown": [
"$TC actions flush action police" "$TC actions flush action police"
] ]
},
{
"id": "cdd7",
"name": "Add valid police action with packets per second rate limit",
"category": [
"actions",
"police"
],
"setup": [
[
"$TC actions flush action police",
0,
1,
255
]
],
"cmdUnderTest": "$TC actions add action police pkts_rate 1000 pkts_burst 200 index 1",
"expExitCode": "0",
"verifyCmd": "$TC actions ls action police",
"matchPattern": "action order [0-9]*: police 0x1 rate 0bit burst 0b mtu 4096Mb pkts_rate 1000 pkts_burst 200",
"matchCount": "1",
"teardown": [
"$TC actions flush action police"
]
},
{
"id": "f5bc",
"name": "Add invalid police action with both bps and pps",
"category": [
"actions",
"police"
],
"setup": [
[
"$TC actions flush action police",
0,
1,
255
]
],
"cmdUnderTest": "$TC actions add action police rate 1kbit burst 10k pkts_rate 1000 pkts_burst 200 index 1",
"expExitCode": "255",
"verifyCmd": "$TC actions ls action police",
"matchPattern": "action order [0-9]*: police 0x1 ",
"matchCount": "0",
"teardown": [
"$TC actions flush action police"
]
} }
] ]
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment