Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/bash
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # Test L3 stats on IP-in-IP GRE tunnel without key.
0005 
0006 # This test uses flat topology for IP tunneling tests. See ipip_lib.sh for more
0007 # details.
0008 
0009 ALL_TESTS="
0010         ping_ipv4
0011         test_stats_rx
0012         test_stats_tx
0013 "
0014 NUM_NETIFS=6
0015 source lib.sh
0016 source ipip_lib.sh
0017 
0018 setup_prepare()
0019 {
0020         h1=${NETIFS[p1]}
0021         ol1=${NETIFS[p2]}
0022 
0023         ul1=${NETIFS[p3]}
0024         ul2=${NETIFS[p4]}
0025 
0026         ol2=${NETIFS[p5]}
0027         h2=${NETIFS[p6]}
0028 
0029         ol1mac=$(mac_get $ol1)
0030 
0031         forwarding_enable
0032         vrf_prepare
0033         h1_create
0034         h2_create
0035         sw1_flat_create gre $ol1 $ul1
0036         sw2_flat_create gre $ol2 $ul2
0037         ip stats set dev g1a l3_stats on
0038         ip stats set dev g2a l3_stats on
0039 }
0040 
0041 cleanup()
0042 {
0043         pre_cleanup
0044 
0045         ip stats set dev g1a l3_stats off
0046         ip stats set dev g2a l3_stats off
0047 
0048         sw2_flat_destroy $ol2 $ul2
0049         sw1_flat_destroy $ol1 $ul1
0050         h2_destroy
0051         h1_destroy
0052 
0053         vrf_cleanup
0054         forwarding_restore
0055 }
0056 
0057 ping_ipv4()
0058 {
0059         RET=0
0060 
0061         ping_test $h1 192.0.2.18 " gre flat"
0062 }
0063 
0064 send_packets_ipv4()
0065 {
0066         # Send 21 packets instead of 20, because the first one might trap and go
0067         # through the SW datapath, which might not bump the HW counter.
0068         $MZ $h1 -c 21 -d 20msec -p 100 \
0069             -a own -b $ol1mac -A 192.0.2.1 -B 192.0.2.18 \
0070             -q -t udp sp=54321,dp=12345
0071 }
0072 
0073 test_stats()
0074 {
0075         local dev=$1; shift
0076         local dir=$1; shift
0077 
0078         local a
0079         local b
0080 
0081         RET=0
0082 
0083         a=$(hw_stats_get l3_stats $dev $dir packets)
0084         send_packets_ipv4
0085         b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \
0086                      hw_stats_get l3_stats $dev $dir packets)
0087         check_err $? "Traffic not reflected in the counter: $a -> $b"
0088 
0089         log_test "Test $dir packets: $prot"
0090 }
0091 
0092 test_stats_tx()
0093 {
0094         test_stats g1a tx
0095 }
0096 
0097 test_stats_rx()
0098 {
0099         test_stats g2a rx
0100 }
0101 
0102 trap cleanup EXIT
0103 
0104 setup_prepare
0105 setup_wait
0106 
0107 tests_run
0108 
0109 exit $EXIT_STATUS