@@ -7,6 +7,7 @@ ALL_TESTS="
77 prio
88 arp_validate
99 num_grat_arp
10+ fail_over_mac
1011"
1112
1213lib_dir=$( dirname " $0 " )
@@ -352,8 +353,8 @@ garp_test()
352353
353354 exp_num=$( echo " ${param} " | cut -f6 -d ' ' )
354355 active_slave=$( cmd_jq " ip -n ${s_ns} -d -j link show bond0" " .[].linkinfo.info_data.active_slave" )
355- slowwait_for_counter $(( exp_num + 5 )) $exp_num \
356- tc_rule_handle_stats_get " dev s${active_slave# eth} ingress" 101 " .packets" " -n ${g_ns} "
356+ slowwait_for_counter $(( exp_num + 5 )) $exp_num tc_rule_handle_stats_get \
357+ " dev s${active_slave# eth} ingress" 101 " .packets" " -n ${g_ns} " & > /dev/null
357358
358359 # check result
359360 real_num=$( tc_rule_handle_stats_get " dev s${active_slave# eth} ingress" 101 " .packets" " -n ${g_ns} " )
@@ -376,6 +377,140 @@ num_grat_arp()
376377 done
377378}
378379
380+ check_all_mac_same ()
381+ {
382+ RET=0
383+ # all slaves should have same mac address (with the first port's mac)
384+ local bond_mac=$( ip -n " $s_ns " -j link show bond0 | jq -r ' .[]["address"]' )
385+ local eth0_mac=$( ip -n " $s_ns " -j link show eth0 | jq -r ' .[]["address"]' )
386+ local eth1_mac=$( ip -n " $s_ns " -j link show eth1 | jq -r ' .[]["address"]' )
387+ local eth2_mac=$( ip -n " $s_ns " -j link show eth2 | jq -r ' .[]["address"]' )
388+ if [ " $bond_mac " != " ${mac[0]} " ] || [ " $eth0_mac " != " $bond_mac " ] || \
389+ [ " $eth1_mac " != " $bond_mac " ] || [ " $eth2_mac " != " $bond_mac " ]; then
390+ RET=1
391+ fi
392+ }
393+
394+ check_bond_mac_same_with_first ()
395+ {
396+ RET=0
397+ # bond mac address should be same with the first added slave
398+ local bond_mac=$( ip -n " $s_ns " -j link show bond0 | jq -r ' .[]["address"]' )
399+ if [ " $bond_mac " != " ${mac[0]} " ]; then
400+ RET=1
401+ fi
402+ }
403+
404+ check_bond_mac_same_with_active ()
405+ {
406+ RET=0
407+ # bond mac address should be same with active slave
408+ local bond_mac=$( ip -n " $s_ns " -j link show bond0 | jq -r ' .[]["address"]' )
409+ local active_slave=$( cmd_jq " ip -n ${s_ns} -d -j link show bond0" " .[].linkinfo.info_data.active_slave" )
410+ local active_slave_mac=$( ip -n " $s_ns " -j link show " $active_slave " | jq -r ' .[]["address"]' )
411+ if [ " $bond_mac " != " $active_slave_mac " ]; then
412+ RET=1
413+ fi
414+ }
415+
416+ check_backup_slave_mac_not_change ()
417+ {
418+ RET=0
419+ # backup slave's mac address is not changed
420+ if ip -n " $s_ns " -d -j link show type bond_slave | jq -e ' .[]
421+ | select(.linkinfo.info_slave_data.state=="BACKUP")
422+ | select(.address != .linkinfo.info_slave_data.perm_hwaddr)' & > /dev/null; then
423+ RET=1
424+ fi
425+ }
426+
427+ check_backup_slave_mac_inherit ()
428+ {
429+ local backup_mac
430+ RET=0
431+
432+ # backup slaves should use mac[1] or mac[2]
433+ local backup_macs=$( ip -n " $s_ns " -d -j link show type bond_slave | \
434+ jq -r ' .[] | select(.linkinfo.info_slave_data.state=="BACKUP") | .address' )
435+ for backup_mac in $backup_macs ; do
436+ if [ " $backup_mac " != " ${mac[1]} " ] && [ " $backup_mac " != " ${mac[2]} " ]; then
437+ RET=1
438+ fi
439+ done
440+ }
441+
442+ check_first_slave_random_mac ()
443+ {
444+ RET=0
445+ # remove the first added slave and added it back
446+ ip -n " $s_ns " link set eth0 nomaster
447+ ip -n " $s_ns " link set eth0 master bond0
448+
449+ # the first slave should use random mac address
450+ eth0_mac=$( ip -n " $s_ns " -j link show eth0 | jq -r ' .[]["address"]' )
451+ [ " $eth0_mac " = " ${mac[0]} " ] && RET=1
452+ log_test " bond fail_over_mac follow" " random first slave mac"
453+
454+ # remove the first slave, the permanent MAC address should be restored back
455+ ip -n " $s_ns " link set eth0 nomaster
456+ eth0_mac=$( ip -n " $s_ns " -j link show eth0 | jq -r ' .[]["address"]' )
457+ [ " $eth0_mac " != " ${mac[0]} " ] && RET=1
458+ }
459+
460+ do_active_backup_failover ()
461+ {
462+ local active_slave=$( cmd_jq " ip -n ${s_ns} -d -j link show bond0" " .[].linkinfo.info_data.active_slave" )
463+ ip -n ${s_ns} link set ${active_slave} down
464+ slowwait 2 active_slave_changed $active_slave
465+ ip -n ${s_ns} link set ${active_slave} up
466+ }
467+
468+ fail_over_mac ()
469+ {
470+ # Bring down the first interface on the switch to force the bond to
471+ # select another active interface instead of the first one that joined.
472+ ip -n " $g_ns " link set s0 down
473+
474+ # fail_over_mac none
475+ bond_reset " mode active-backup miimon 100 fail_over_mac 0"
476+ check_all_mac_same
477+ log_test " fail_over_mac 0" " all slaves have same mac"
478+ do_active_backup_failover
479+ check_all_mac_same
480+ log_test " fail_over_mac 0" " failover: all slaves have same mac"
481+
482+ # fail_over_mac active
483+ bond_reset " mode active-backup miimon 100 fail_over_mac 1"
484+ check_bond_mac_same_with_active
485+ log_test " fail_over_mac 1" " bond mac is same with active slave mac"
486+ check_backup_slave_mac_not_change
487+ log_test " fail_over_mac 1" " backup slave mac is not changed"
488+ do_active_backup_failover
489+ check_bond_mac_same_with_active
490+ log_test " fail_over_mac 1" " failover: bond mac is same with active slave mac"
491+ check_backup_slave_mac_not_change
492+ log_test " fail_over_mac 1" " failover: backup slave mac is not changed"
493+
494+ # fail_over_mac follow
495+ bond_reset " mode active-backup miimon 100 fail_over_mac 2"
496+ check_bond_mac_same_with_first
497+ log_test " fail_over_mac 2" " bond mac is same with first slave mac"
498+ check_bond_mac_same_with_active
499+ log_test " fail_over_mac 2" " bond mac is same with active slave mac"
500+ check_backup_slave_mac_inherit
501+ log_test " fail_over_mac 2" " backup slave mac inherit"
502+ do_active_backup_failover
503+ check_bond_mac_same_with_first
504+ log_test " fail_over_mac 2" " failover: bond mac is same with first slave mac"
505+ check_bond_mac_same_with_active
506+ log_test " fail_over_mac 2" " failover: bond mac is same with active slave mac"
507+ check_backup_slave_mac_inherit
508+ log_test " fail_over_mac 2" " failover: backup slave mac inherit"
509+ check_first_slave_random_mac
510+ log_test " fail_over_mac 2" " first slave mac random"
511+
512+ }
513+
379514trap cleanup EXIT
380515
381516setup_prepare
0 commit comments