selftests: mlxsw: spectrum-2: Add simple delta test
[linux-2.6-block.git] / tools / testing / selftests / drivers / net / mlxsw / spectrum-2 / tc_flower.sh
index 3b75180f455d58a63ca4daa308365054e8edc65b..00ae99fbc2536a2407edc3d92a2b42e6a5bd2728 100755 (executable)
@@ -8,7 +8,7 @@
 lib_dir=$(dirname $0)/../../../../net/forwarding
 
 ALL_TESTS="single_mask_test identical_filters_test two_masks_test \
-       multiple_masks_test ctcam_edge_cases_test"
+       multiple_masks_test ctcam_edge_cases_test delta_simple_test"
 NUM_NETIFS=2
 source $lib_dir/tc_common.sh
 source $lib_dir/lib.sh
@@ -142,7 +142,7 @@ two_masks_test()
        tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \
                $tcflags dst_ip 192.0.2.2 action drop
        tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
-               $tcflags dst_ip 192.0.0.0/16 action drop
+               $tcflags dst_ip 192.0.0.0/8 action drop
 
        $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
                -t ip -q
@@ -235,7 +235,7 @@ ctcam_two_atcam_masks_test()
                $tcflags dst_ip 192.0.2.2 action drop
        # Filter goes into A-TCAM
        tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \
-               $tcflags dst_ip 192.0.2.0/24 action drop
+               $tcflags dst_ip 192.0.0.0/16 action drop
 
        $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
                -t ip -q
@@ -324,6 +324,86 @@ ctcam_edge_cases_test()
        ctcam_no_atcam_masks_test
 }
 
+tp_record()
+{
+       local tracepoint=$1
+       local cmd=$2
+
+       perf record -q -e $tracepoint $cmd
+       return $?
+}
+
+tp_check_hits()
+{
+       local tracepoint=$1
+       local count=$2
+
+       perf_output=`perf script -F trace:event,trace`
+       hits=`echo $perf_output | grep "$tracepoint:" | wc -l`
+       if [[ "$count" -ne "$hits" ]]; then
+               return 1
+       fi
+       return 0
+}
+
+delta_simple_test()
+{
+       # The first filter will create eRP, the second filter will fit into
+       # the first eRP with delta. Remove the first rule then and check that
+        # the eRP stays (referenced by the second filter).
+
+       RET=0
+
+       if [[ "$tcflags" != "skip_sw" ]]; then
+               return 0;
+       fi
+
+       tp_record "objagg:*" "tc filter add dev $h2 ingress protocol ip \
+                  pref 1 handle 101 flower $tcflags dst_ip 192.0.0.0/24 \
+                  action drop"
+       tp_check_hits "objagg:objagg_obj_root_create" 1
+       check_err $? "eRP was not created"
+
+       tp_record "objagg:*" "tc filter add dev $h2 ingress protocol ip \
+                  pref 2 handle 102 flower $tcflags dst_ip 192.0.2.2 \
+                  action drop"
+       tp_check_hits "objagg:objagg_obj_root_create" 0
+       check_err $? "eRP was incorrectly created"
+       tp_check_hits "objagg:objagg_obj_parent_assign" 1
+       check_err $? "delta was not created"
+
+       $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
+               -t ip -q
+
+       tc_check_packets "dev $h2 ingress" 101 1
+       check_fail $? "Matched a wrong filter"
+
+       tc_check_packets "dev $h2 ingress" 102 1
+       check_err $? "Did not match on correct filter"
+
+       tp_record "objagg:*" "tc filter del dev $h2 ingress protocol ip \
+                  pref 1 handle 101 flower"
+       tp_check_hits "objagg:objagg_obj_root_destroy" 0
+       check_err $? "eRP was incorrectly destroyed"
+       tp_check_hits "objagg:objagg_obj_parent_unassign" 0
+       check_err $? "delta was incorrectly destroyed"
+
+       $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \
+               -t ip -q
+
+       tc_check_packets "dev $h2 ingress" 102 2
+       check_err $? "Did not match on correct filter after the first was removed"
+
+       tp_record "objagg:*" "tc filter del dev $h2 ingress protocol ip \
+                  pref 2 handle 102 flower"
+       tp_check_hits "objagg:objagg_obj_parent_unassign" 1
+       check_err $? "delta was not destroyed"
+       tp_check_hits "objagg:objagg_obj_root_destroy" 1
+       check_err $? "eRP was not destroyed"
+
+       log_test "delta simple test ($tcflags)"
+}
+
 setup_prepare()
 {
        h1=${NETIFS[p1]}