Please execute the bridge configuration script first.
root@localhost:~# vi /test_dir_new/switch_with_bridge.sh
#!/bin/bash
#
# Simple switch configuration
#
# Assume both ENETC and Felix drivers are already loaded
#
BRIDGE=br0
MAC_ROOT=bc:8d:bf:7c:5b
SW_NETNS=swns
EXEC_SWNS="ip netns exec $SW_NETNS"
# Create bridge namespace
ip netns add $SW_NETNS
# Create bridge device in net namespace
$EXEC_SWNS ip link add name $BRIDGE type bridge
$EXEC_SWNS ip link set $BRIDGE up
# Configure switch ports
# * set MAC address
# * bring up interface
# * move net device into the bridge net namespace
# * set bridge device as master
swps=($(ls /sys/bus/pci/devices/0000:00:00.5/net/))
nr=${#swps[@]}
for (( i=0; i<$nr; i++ ))
do
echo "adding ${swps[$i]} to brigde .."
ip link set ${swps[$i]} address $MAC_ROOT:$(echo "${swps[$i]}" | tr -dc '0-9')
ip link set ${swps[$i]} netns $SW_NETNS
$EXEC_SWNS ip link set ${swps[$i]} master $BRIDGE
$EXEC_SWNS ip link set ${swps[$i]} up
done
# bring up ENETC ports connected to switch ports
enetc2=$(ls /sys/bus/pci/devices/0000:00:00.2/net/)
ip link set $enetc2 up
# move ENETC port connected to switch CPU port in bridge ns
enetc3=$(ls /sys/bus/pci/devices/0000:00:00.6/net/)
ip link set $enetc3 netns $SW_NETNS
$EXEC_SWNS ip link set $enetc3 up
# Check configuration
$EXEC_SWNS bridge link show
root@localhost:~#
root@localhost:~# uname -a;stty columns 2000;echo "7 4 1 7" > /proc/sys/kernel/printk
Linux localhost 4.14.47-00650-g6a585bc218f4-dirty #1 SMP PREEMPT Wed May 8 16:18:37 CST 2019 aarch64 aarch64 aarch64 GNU/Linux
root@localhost:~#
root@localhost:~# bash +x /test_dir_new/switch_with_bridge.sh
adding swp0 to brigde ..
[ 808.096561] br0: port 1(swp0) entered blocking state
[ 808.101591] br0: port 1(swp0) entered disabled state
[ 808.106735] device swp0 entered promiscuous mode
[ 808.222629] Vitesse VSC8514 1f8100000:10: attached PHY driver [Vitesse VSC8514] (mii_bus:phy_addr=1f8100000:10, irq=POLL)
[ 808.233775] IPv6: ADDRCONF(NETDEV_UP): swp0: link is not ready
[ 808.239655] br0: port 1(swp0) entered blocking state
[ 808.244648] br0: port 1(swp0) entered forwarding state
[ 808.249847] 8021q: adding VLAN 0 to HW filter on device swp0
adding swp1 to brigde ..
[ 808.336382] br0: port 2(swp1) entered blocking state
[ 808.341469] br0: port 2(swp1) entered disabled state
[ 808.346923] device swp1 entered promiscuous mode
[ 808.458632] Vitesse VSC8514 1f8100000:11: attached PHY driver [Vitesse VSC8514] (mii_bus:phy_addr=1f8100000:11, irq=POLL)
[ 808.469854] IPv6: ADDRCONF(NETDEV_UP): swp1: link is not ready
[ 808.475729] br0: port 2(swp1) entered blocking state
[ 808.480722] br0: port 2(swp1) entered forwarding state
[ 808.485911] 8021q: adding VLAN 0 to HW filter on device swp1
adding swp2 to brigde ..
[ 808.573011] br0: port 3(swp2) entered blocking state
[ 808.578148] br0: port 3(swp2) entered disabled state
[ 808.583846] device swp2 entered promiscuous mode
[ 808.706586] Vitesse VSC8514 1f8100000:12: attached PHY driver [Vitesse VSC8514] (mii_bus:phy_addr=1f8100000:12, irq=POLL)
[ 808.717801] IPv6: ADDRCONF(NETDEV_UP): swp2: link is not ready
[ 808.724954] br0: port 3(swp2) entered blocking state
[ 808.729950] br0: port 3(swp2) entered forwarding state
[ 808.735154] 8021q: adding VLAN 0 to HW filter on device swp2
adding swp3 to brigde ..
[ 808.810009] br0: port 4(swp3) entered blocking state
[ 808.815059] br0: port 4(swp3) entered disabled state
[ 808.820249] device swp3 entered promiscuous mode
[ 808.930592] Vitesse VSC8514 1f8100000:13: attached PHY driver [Vitesse VSC8514] (mii_bus:phy_addr=1f8100000:13, irq=POLL)
[ 808.941745] IPv6: ADDRCONF(NETDEV_UP): swp3: link is not ready
[ 808.948096] br0: port 4(swp3) entered blocking state
[ 808.953099] br0: port 4(swp3) entered forwarding state
[ 808.958297] 8021q: adding VLAN 0 to HW filter on device swp3
adding swp4 to brigde ..
[ 809.052551] br0: port 5(swp4) entered blocking state
[ 809.057642] br0: port 5(swp4) entered disabled state
[ 809.062828] device swp4 entered promiscuous mode
[ 809.120123] Generic PHY fixed-0:02: attached PHY driver [Generic PHY] (mii_bus:phy_addr=fixed-0:02, irq=POLL)
[ 809.130249] IPv6: ADDRCONF(NETDEV_UP): swp4: link is not ready
[ 809.136148] br0: port 5(swp4) entered blocking state
[ 809.141141] br0: port 5(swp4) entered forwarding state
[ 809.146495] 8021q: adding VLAN 0 to HW filter on device swp4
[ 809.152259] br0: port 1(swp0) entered disabled state
[ 809.157373] br0: port 2(swp1) entered disabled state
[ 809.162465] br0: port 3(swp2) entered disabled state
[ 809.167563] br0: port 4(swp3) entered disabled state
[ 809.172653] br0: port 5(swp4) entered disabled state
adding swp5 to brigde ..
[ 809.229772] br0: port 6(swp5) entered blocking state
[ 809.234848] br0: port 6(swp5) entered disabled state
[ 809.239996] device swp5 entered promiscuous mode
[ 809.266968] mscc_felix 0000:00:00.5 swp0: Link is Down
[ 809.282439] Generic PHY fixed-0:03: attached PHY driver [Generic PHY] (mii_bus:phy_addr=fixed-0:03, irq=POLL)
[ 809.292558] IPv6: ADDRCONF(NETDEV_UP): swp5: link is not ready
[ 809.298573] br0: port 6(swp5) entered blocking state
[ 809.303568] br0: port 6(swp5) entered forwarding state
[ 809.308761] 8021q: adding VLAN 0 to HW filter on device swp5
[ 809.345059] Generic PHY fixed-0:00: attached PHY driver [Generic PHY] (mii_bus:phy_addr=fixed-0:00, irq=POLL)
[ 809.359928] IPv6: ADDRCONF(NETDEV_UP): eno2: link is not ready
[ 809.365972] 8021q: adding VLAN 0 to HW filter on device eno2
[ 809.416879] Generic PHY fixed-0:01: attached PHY driver [Generic PHY] (mii_bus:phy_addr=fixed-0:01, irq=POLL)
[ 809.431091] IPv6: ADDRCONF(NETDEV_UP): eno3: link is not ready
[ 809.436975] 8021q: adding VLAN 0 to HW filter on device eno3
[ 809.487020] mscc_felix 0000:00:00.5 swp1: Link is Down
7: swp0 state DOWN : <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1468 master br0 state disabled priority 32 cost 100
8: swp1 state DOWN : <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1468 master br0 state disabled priority 32 cost 100
9: swp2 state DOWN : <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1468 master br0 state disabled priority 32 cost 100
10: swp3 state DOWN : <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1468 master br0 state disabled priority 32 cost 100
11: swp4 state DOWN : <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1468 master br0 state disabled priority 32 cost 100
12: swp5 state UNKNOWN : <BROADCAST,MULTICAST,UP> mtu 1468 master br0 state forwarding priority 32 cost 100
root@localhost:~# [ 809.743175] mscc_felix 0000:00:00.5 swp2: Link is Down
[ 809.967156] mscc_felix 0000:00:00.5 swp3: Link is Down
[ 810.158491] mscc_felix 0000:00:00.5 swp4: Link is Up - 1Gbps/Full - flow control off
[ 810.166385] br0: port 6(swp5) entered disabled state
[ 810.171524] IPv6: ADDRCONF(NETDEV_CHANGE): swp4: link becomes ready
[ 810.177874] br0: port 5(swp4) entered blocking state
[ 810.182863] br0: port 5(swp4) entered forwarding state
[ 810.318395] mscc_felix 0000:00:00.5 swp5: Link is Up - 1Gbps/Full - flow control off
[ 810.326250] IPv6: ADDRCONF(NETDEV_CHANGE): swp5: link becomes ready
[ 810.326398] br0: port 6(swp5) entered blocking state
[ 810.326410] br0: port 6(swp5) entered forwarding state
[ 810.382487] fsl_enetc 0000:00:00.2 eno2: Link is Up - 1Gbps/Full - flow control off
[ 810.390262] IPv6: ADDRCONF(NETDEV_CHANGE): eno2: link becomes ready
[ 810.446481] fsl_enetc 0000:00:00.6 eno3: Link is Up - 1Gbps/Full - flow control off
[ 810.454256] IPv6: ADDRCONF(NETDEV_CHANGE): eno3: link becomes ready
root@localhost:~#
Thanks,
Yiping