0001
0002
0003 mirror_install()
0004 {
0005 local from_dev=$1; shift
0006 local direction=$1; shift
0007 local to_dev=$1; shift
0008 local filter=$1; shift
0009
0010 tc filter add dev $from_dev $direction \
0011 pref 1000 $filter \
0012 action mirred egress mirror dev $to_dev
0013 }
0014
0015 mirror_uninstall()
0016 {
0017 local from_dev=$1; shift
0018 local direction=$1; shift
0019
0020 tc filter del dev $swp1 $direction pref 1000
0021 }
0022
0023 is_ipv6()
0024 {
0025 local addr=$1; shift
0026
0027 [[ -z ${addr//[0-9a-fA-F:]/} ]]
0028 }
0029
0030 mirror_test()
0031 {
0032 local vrf_name=$1; shift
0033 local sip=$1; shift
0034 local dip=$1; shift
0035 local dev=$1; shift
0036 local pref=$1; shift
0037 local expect=$1; shift
0038
0039 if is_ipv6 $dip; then
0040 local proto=-6
0041 local type="icmp6 type=128"
0042 else
0043 local proto=
0044 local type="icmp echoreq"
0045 fi
0046
0047 local t0=$(tc_rule_stats_get $dev $pref)
0048 $MZ $proto $vrf_name ${sip:+-A $sip} -B $dip -a own -b bc -q \
0049 -c 10 -d 100msec -t $type
0050 sleep 0.5
0051 local t1=$(tc_rule_stats_get $dev $pref)
0052 local delta=$((t1 - t0))
0053
0054 ((expect <= delta && delta <= expect + 2))
0055 check_err $? "Expected to capture $expect packets, got $delta."
0056 }
0057
0058 do_test_span_dir_ips()
0059 {
0060 local expect=$1; shift
0061 local dev=$1; shift
0062 local direction=$1; shift
0063 local ip1=$1; shift
0064 local ip2=$1; shift
0065
0066 icmp_capture_install $dev
0067 mirror_test v$h1 $ip1 $ip2 $dev 100 $expect
0068 mirror_test v$h2 $ip2 $ip1 $dev 100 $expect
0069 icmp_capture_uninstall $dev
0070 }
0071
0072 quick_test_span_dir_ips()
0073 {
0074 do_test_span_dir_ips 10 "$@"
0075 }
0076
0077 fail_test_span_dir_ips()
0078 {
0079 do_test_span_dir_ips 0 "$@"
0080 }
0081
0082 test_span_dir_ips()
0083 {
0084 local dev=$1; shift
0085 local direction=$1; shift
0086 local forward_type=$1; shift
0087 local backward_type=$1; shift
0088 local ip1=$1; shift
0089 local ip2=$1; shift
0090
0091 quick_test_span_dir_ips "$dev" "$direction" "$ip1" "$ip2"
0092
0093 icmp_capture_install $dev "type $forward_type"
0094 mirror_test v$h1 $ip1 $ip2 $dev 100 10
0095 icmp_capture_uninstall $dev
0096
0097 icmp_capture_install $dev "type $backward_type"
0098 mirror_test v$h2 $ip2 $ip1 $dev 100 10
0099 icmp_capture_uninstall $dev
0100 }
0101
0102 fail_test_span_dir()
0103 {
0104 fail_test_span_dir_ips "$@" 192.0.2.1 192.0.2.2
0105 }
0106
0107 test_span_dir()
0108 {
0109 test_span_dir_ips "$@" 192.0.2.1 192.0.2.2
0110 }
0111
0112 do_test_span_vlan_dir_ips()
0113 {
0114 local expect=$1; shift
0115 local dev=$1; shift
0116 local vid=$1; shift
0117 local direction=$1; shift
0118 local ul_proto=$1; shift
0119 local ip1=$1; shift
0120 local ip2=$1; shift
0121
0122
0123
0124
0125 vlan_capture_install $dev "skip_hw vlan_id $vid vlan_ethtype $ul_proto"
0126 mirror_test v$h1 $ip1 $ip2 $dev 100 $expect
0127 mirror_test v$h2 $ip2 $ip1 $dev 100 $expect
0128 vlan_capture_uninstall $dev
0129 }
0130
0131 quick_test_span_vlan_dir_ips()
0132 {
0133 do_test_span_vlan_dir_ips 10 "$@"
0134 }
0135
0136 fail_test_span_vlan_dir_ips()
0137 {
0138 do_test_span_vlan_dir_ips 0 "$@"
0139 }
0140
0141 quick_test_span_vlan_dir()
0142 {
0143 quick_test_span_vlan_dir_ips "$@" 192.0.2.1 192.0.2.2
0144 }
0145
0146 fail_test_span_vlan_dir()
0147 {
0148 fail_test_span_vlan_dir_ips "$@" 192.0.2.1 192.0.2.2
0149 }