@@ -79,6 +79,7 @@ CONTROL_PATH_TESTS="
7979 dump_ipv6_ipv4
8080 dump_ipv4_ipv6
8181 dump_ipv6_ipv6
82+ flush
8283"
8384
8485DATA_PATH_TESTS="
@@ -968,6 +969,202 @@ dump_ipv6_ipv6()
968969 dump_common $ns1 $local_addr $remote_prefix $fn
969970}
970971
972+ flush ()
973+ {
974+ local num_entries
975+
976+ echo
977+ echo " Control path: Flush"
978+ echo " -------------------"
979+
980+ # Add entries with different attributes and check that they are all
981+ # flushed when the flush command is given with no parameters.
982+
983+ # Different source VNI.
984+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
985+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.2 permanent dst 198.51.100.1 src_vni 10011"
986+
987+ # Different routing protocol.
988+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.3 permanent proto bgp dst 198.51.100.1 src_vni 10010"
989+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.4 permanent proto zebra dst 198.51.100.1 src_vni 10010"
990+
991+ # Different destination IP.
992+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.5 permanent dst 198.51.100.1 src_vni 10010"
993+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.6 permanent dst 198.51.100.2 src_vni 10010"
994+
995+ # Different destination port.
996+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.7 permanent dst 198.51.100.1 dst_port 11111 src_vni 10010"
997+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.8 permanent dst 198.51.100.1 dst_port 22222 src_vni 10010"
998+
999+ # Different VNI.
1000+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.9 permanent dst 198.51.100.1 vni 10010 src_vni 10010"
1001+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.10 permanent dst 198.51.100.1 vni 10020 src_vni 10010"
1002+
1003+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0"
1004+ num_entries=$( bridge -n $ns1_v4 mdb show dev vx0 | wc -l)
1005+ [[ $num_entries -eq 0 ]]
1006+ log_test $? 0 " Flush all"
1007+
1008+ # Check that entries are flushed when port is specified as the VXLAN
1009+ # device and that an error is returned when port is specified as a
1010+ # different net device.
1011+
1012+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1013+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.2 src_vni 10010"
1014+
1015+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 port vx0"
1016+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010"
1017+ log_test $? 254 " Flush by port"
1018+
1019+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 port veth0"
1020+ log_test $? 255 " Flush by wrong port"
1021+
1022+ # Check that when flushing by source VNI only entries programmed with
1023+ # the specified source VNI are flushed and the rest are not.
1024+
1025+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1026+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.2 src_vni 10010"
1027+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10011"
1028+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.2 src_vni 10011"
1029+
1030+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 src_vni 10010"
1031+
1032+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010"
1033+ log_test $? 254 " Flush by specified source VNI"
1034+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10011"
1035+ log_test $? 0 " Flush by unspecified source VNI"
1036+
1037+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0"
1038+
1039+ # Check that all entries are flushed when "permanent" is specified and
1040+ # that an error is returned when "nopermanent" is specified.
1041+
1042+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1043+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.2 src_vni 10010"
1044+
1045+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 permanent"
1046+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010"
1047+ log_test $? 254 " Flush by \" permanent\" state"
1048+
1049+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 nopermanent"
1050+ log_test $? 255 " Flush by \" nopermanent\" state"
1051+
1052+ # Check that when flushing by routing protocol only entries programmed
1053+ # with the specified routing protocol are flushed and the rest are not.
1054+
1055+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent proto bgp dst 198.51.100.1 src_vni 10010"
1056+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent proto zebra dst 198.51.100.2 src_vni 10010"
1057+
1058+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 proto bgp"
1059+
1060+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \" proto bgp\" "
1061+ log_test $? 1 " Flush by specified routing protocol"
1062+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \" proto zebra\" "
1063+ log_test $? 0 " Flush by unspecified routing protocol"
1064+
1065+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0"
1066+
1067+ # Check that when flushing by destination IP only entries programmed
1068+ # with the specified destination IP are flushed and the rest are not.
1069+
1070+ # IPv4.
1071+
1072+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1073+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.2 src_vni 10010"
1074+
1075+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 dst 198.51.100.2"
1076+
1077+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.2"
1078+ log_test $? 1 " Flush by specified destination IP - IPv4"
1079+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.1"
1080+ log_test $? 0 " Flush by unspecified destination IP - IPv4"
1081+
1082+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0"
1083+
1084+ # IPv6.
1085+
1086+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 2001:db8:1000::1 src_vni 10010"
1087+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 2001:db8:1000::2 src_vni 10010"
1088+
1089+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 dst 2001:db8:1000::2"
1090+
1091+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 2001:db8:1000::2"
1092+ log_test $? 1 " Flush by specified destination IP - IPv6"
1093+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 2001:db8:1000::1"
1094+ log_test $? 0 " Flush by unspecified destination IP - IPv6"
1095+
1096+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0"
1097+
1098+ # Check that when flushing by UDP destination port only entries
1099+ # programmed with the specified port are flushed and the rest are not.
1100+
1101+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst_port 11111 dst 198.51.100.1 src_vni 10010"
1102+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst_port 22222 dst 198.51.100.2 src_vni 10010"
1103+
1104+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 dst_port 11111"
1105+
1106+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \" dst_port 11111\" "
1107+ log_test $? 1 " Flush by specified UDP destination port"
1108+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \" dst_port 22222\" "
1109+ log_test $? 0 " Flush by unspecified UDP destination port"
1110+
1111+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0"
1112+
1113+ # When not specifying a UDP destination port for an entry, traffic is
1114+ # encapsulated with the device's UDP destination port. Check that when
1115+ # flushing by the device's UDP destination port only entries programmed
1116+ # with this port are flushed and the rest are not.
1117+
1118+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1119+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst_port 22222 dst 198.51.100.2 src_vni 10010"
1120+
1121+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 dst_port 4789"
1122+
1123+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.1"
1124+ log_test $? 1 " Flush by device's UDP destination port"
1125+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.2"
1126+ log_test $? 0 " Flush by unspecified UDP destination port"
1127+
1128+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0"
1129+
1130+ # Check that when flushing by destination VNI only entries programmed
1131+ # with the specified destination VNI are flushed and the rest are not.
1132+
1133+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent vni 20010 dst 198.51.100.1 src_vni 10010"
1134+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent vni 20011 dst 198.51.100.2 src_vni 10010"
1135+
1136+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 vni 20010"
1137+
1138+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \" vni 20010\" "
1139+ log_test $? 1 " Flush by specified destination VNI"
1140+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep \" vni 20011\" "
1141+ log_test $? 0 " Flush by unspecified destination VNI"
1142+
1143+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0"
1144+
1145+ # When not specifying a destination VNI for an entry, traffic is
1146+ # encapsulated with the source VNI. Check that when flushing by a
1147+ # destination VNI that is equal to the source VNI only such entries are
1148+ # flushed and the rest are not.
1149+
1150+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent dst 198.51.100.1 src_vni 10010"
1151+ run_cmd " bridge -n $ns1_v4 mdb add dev vx0 port vx0 grp 239.1.1.1 permanent vni 20010 dst 198.51.100.2 src_vni 10010"
1152+
1153+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 vni 10010"
1154+
1155+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.1"
1156+ log_test $? 1 " Flush by destination VNI equal to source VNI"
1157+ run_cmd " bridge -n $ns1_v4 -d -s mdb get dev vx0 grp 239.1.1.1 src_vni 10010 | grep 198.51.100.2"
1158+ log_test $? 0 " Flush by unspecified destination VNI"
1159+
1160+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0"
1161+
1162+ # Test that an error is returned when trying to flush using VLAN ID.
1163+
1164+ run_cmd " bridge -n $ns1_v4 mdb flush dev vx0 vid 10"
1165+ log_test $? 255 " Flush by VLAN ID"
1166+ }
1167+
9711168# ###############################################################################
9721169# Tests - Data path
9731170
@@ -2292,9 +2489,9 @@ if [ ! -x "$(command -v jq)" ]; then
22922489 exit $ksft_skip
22932490fi
22942491
2295- bridge mdb help 2>&1 | grep -q " get "
2492+ bridge mdb help 2>&1 | grep -q " flush "
22962493if [ $? -ne 0 ]; then
2297- echo " SKIP: iproute2 bridge too old, missing VXLAN MDB get support"
2494+ echo " SKIP: iproute2 bridge too old, missing VXLAN MDB flush support"
22982495 exit $ksft_skip
22992496fi
23002497
0 commit comments