0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 ALL_TESTS="
0027 ping_ipv4
0028 ping_ipv6
0029 test_stats_rx_ipv4
0030 test_stats_tx_ipv4
0031 test_stats_rx_ipv6
0032 test_stats_tx_ipv6
0033 respin_enablement
0034 test_stats_rx_ipv4
0035 test_stats_tx_ipv4
0036 test_stats_rx_ipv6
0037 test_stats_tx_ipv6
0038 reapply_config
0039 ping_ipv4
0040 ping_ipv6
0041 test_stats_rx_ipv4
0042 test_stats_tx_ipv4
0043 test_stats_rx_ipv6
0044 test_stats_tx_ipv6
0045 test_stats_report_rx
0046 test_stats_report_tx
0047 test_destroy_enabled
0048 test_double_enable
0049 "
0050 NUM_NETIFS=4
0051 source lib.sh
0052
0053 h1_create()
0054 {
0055 simple_if_init $h1
0056 vlan_create $h1 200 v$h1 192.0.2.1/28 2001:db8:1::1/64
0057 ip route add 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.2
0058 ip -6 route add 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2
0059 }
0060
0061 h1_destroy()
0062 {
0063 ip -6 route del 2001:db8:2::/64 vrf v$h1 nexthop via 2001:db8:1::2
0064 ip route del 192.0.2.16/28 vrf v$h1 nexthop via 192.0.2.2
0065 vlan_destroy $h1 200
0066 simple_if_fini $h1
0067 }
0068
0069 h2_create()
0070 {
0071 simple_if_init $h2
0072 vlan_create $h2 200 v$h2 192.0.2.18/28 2001:db8:2::1/64
0073 ip route add 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.17
0074 ip -6 route add 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::2
0075 }
0076
0077 h2_destroy()
0078 {
0079 ip -6 route del 2001:db8:1::/64 vrf v$h2 nexthop via 2001:db8:2::2
0080 ip route del 192.0.2.0/28 vrf v$h2 nexthop via 192.0.2.17
0081 vlan_destroy $h2 200
0082 simple_if_fini $h2
0083 }
0084
0085 router_rp1_200_create()
0086 {
0087 ip link add name $rp1.200 up \
0088 link $rp1 addrgenmode eui64 type vlan id 200
0089 ip address add dev $rp1.200 192.0.2.2/28
0090 ip address add dev $rp1.200 2001:db8:1::2/64
0091 ip stats set dev $rp1.200 l3_stats on
0092 }
0093
0094 router_rp1_200_destroy()
0095 {
0096 ip stats set dev $rp1.200 l3_stats off
0097 ip address del dev $rp1.200 2001:db8:1::2/64
0098 ip address del dev $rp1.200 192.0.2.2/28
0099 ip link del dev $rp1.200
0100 }
0101
0102 router_create()
0103 {
0104 ip link set dev $rp1 up
0105 router_rp1_200_create
0106
0107 ip link set dev $rp2 up
0108 vlan_create $rp2 200 "" 192.0.2.17/28 2001:db8:2::2/64
0109 }
0110
0111 router_destroy()
0112 {
0113 vlan_destroy $rp2 200
0114 ip link set dev $rp2 down
0115
0116 router_rp1_200_destroy
0117 ip link set dev $rp1 down
0118 }
0119
0120 setup_prepare()
0121 {
0122 h1=${NETIFS[p1]}
0123 rp1=${NETIFS[p2]}
0124
0125 rp2=${NETIFS[p3]}
0126 h2=${NETIFS[p4]}
0127
0128 rp1mac=$(mac_get $rp1)
0129 rp2mac=$(mac_get $rp2)
0130
0131 vrf_prepare
0132
0133 h1_create
0134 h2_create
0135
0136 router_create
0137
0138 forwarding_enable
0139 }
0140
0141 cleanup()
0142 {
0143 pre_cleanup
0144
0145 forwarding_restore
0146
0147 router_destroy
0148
0149 h2_destroy
0150 h1_destroy
0151
0152 vrf_cleanup
0153 }
0154
0155 ping_ipv4()
0156 {
0157 ping_test $h1.200 192.0.2.18 " IPv4"
0158 }
0159
0160 ping_ipv6()
0161 {
0162 ping_test $h1.200 2001:db8:2::1 " IPv6"
0163 }
0164
0165 send_packets_rx_ipv4()
0166 {
0167
0168
0169 $MZ $h1.200 -c 21 -d 20msec -p 100 \
0170 -a own -b $rp1mac -A 192.0.2.1 -B 192.0.2.18 \
0171 -q -t udp sp=54321,dp=12345
0172 }
0173
0174 send_packets_rx_ipv6()
0175 {
0176 $MZ $h1.200 -6 -c 21 -d 20msec -p 100 \
0177 -a own -b $rp1mac -A 2001:db8:1::1 -B 2001:db8:2::1 \
0178 -q -t udp sp=54321,dp=12345
0179 }
0180
0181 send_packets_tx_ipv4()
0182 {
0183 $MZ $h2.200 -c 21 -d 20msec -p 100 \
0184 -a own -b $rp2mac -A 192.0.2.18 -B 192.0.2.1 \
0185 -q -t udp sp=54321,dp=12345
0186 }
0187
0188 send_packets_tx_ipv6()
0189 {
0190 $MZ $h2.200 -6 -c 21 -d 20msec -p 100 \
0191 -a own -b $rp2mac -A 2001:db8:2::1 -B 2001:db8:1::1 \
0192 -q -t udp sp=54321,dp=12345
0193 }
0194
0195 ___test_stats()
0196 {
0197 local dir=$1; shift
0198 local prot=$1; shift
0199
0200 local a
0201 local b
0202
0203 a=$(hw_stats_get l3_stats $rp1.200 ${dir} packets)
0204 send_packets_${dir}_${prot}
0205 "$@"
0206 b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \
0207 hw_stats_get l3_stats $rp1.200 ${dir} packets)
0208 check_err $? "Traffic not reflected in the counter: $a -> $b"
0209 }
0210
0211 __test_stats()
0212 {
0213 local dir=$1; shift
0214 local prot=$1; shift
0215
0216 RET=0
0217 ___test_stats "$dir" "$prot"
0218 log_test "Test $dir packets: $prot"
0219 }
0220
0221 test_stats_rx_ipv4()
0222 {
0223 __test_stats rx ipv4
0224 }
0225
0226 test_stats_tx_ipv4()
0227 {
0228 __test_stats tx ipv4
0229 }
0230
0231 test_stats_rx_ipv6()
0232 {
0233 __test_stats rx ipv6
0234 }
0235
0236 test_stats_tx_ipv6()
0237 {
0238 __test_stats tx ipv6
0239 }
0240
0241
0242
0243 respin_enablement()
0244 {
0245 log_info "Turning stats off and on again"
0246 ip stats set dev $rp1.200 l3_stats off
0247 ip stats set dev $rp1.200 l3_stats on
0248 }
0249
0250
0251
0252
0253 reapply_config()
0254 {
0255 log_info "Reapplying configuration"
0256
0257 router_rp1_200_destroy
0258
0259 ip link add name $rp1.200 link $rp1 addrgenmode none type vlan id 200
0260 ip stats set dev $rp1.200 l3_stats on
0261 ip link set dev $rp1.200 up addrgenmode eui64
0262 ip address add dev $rp1.200 192.0.2.2/28
0263 ip address add dev $rp1.200 2001:db8:1::2/64
0264 }
0265
0266 __test_stats_report()
0267 {
0268 local dir=$1; shift
0269 local prot=$1; shift
0270
0271 local a
0272 local b
0273
0274 RET=0
0275
0276 a=$(hw_stats_get l3_stats $rp1.200 ${dir} packets)
0277 send_packets_${dir}_${prot}
0278 ip address flush dev $rp1.200
0279 b=$(busywait "$TC_HIT_TIMEOUT" until_counter_is ">= $a + 20" \
0280 hw_stats_get l3_stats $rp1.200 ${dir} packets)
0281 check_err $? "Traffic not reflected in the counter: $a -> $b"
0282 log_test "Test ${dir} packets: stats pushed on loss of L3"
0283
0284 ip stats set dev $rp1.200 l3_stats off
0285 ip link del dev $rp1.200
0286 router_rp1_200_create
0287 }
0288
0289 test_stats_report_rx()
0290 {
0291 __test_stats_report rx ipv4
0292 }
0293
0294 test_stats_report_tx()
0295 {
0296 __test_stats_report tx ipv4
0297 }
0298
0299 test_destroy_enabled()
0300 {
0301 RET=0
0302
0303 ip link del dev $rp1.200
0304 router_rp1_200_create
0305
0306 log_test "Destroy l3_stats-enabled netdev"
0307 }
0308
0309 test_double_enable()
0310 {
0311 RET=0
0312 ___test_stats rx ipv4 \
0313 ip stats set dev $rp1.200 l3_stats on
0314 log_test "Test stat retention across a spurious enablement"
0315 }
0316
0317 trap cleanup EXIT
0318
0319 setup_prepare
0320 setup_wait
0321
0322 tests_run
0323
0324 exit $EXIT_STATUS