bridge

Browse source code on GitHub

Overview

Example on testing/debugging Ethernet bridge

The source code for this sample application can be found at: samples/net/ethernet/bridge.

Building and Running

Follow these steps to build the bridge sample application:

west build -b <board to use> samples/net/ethernet/bridge -- -DCONF_FILE=prj.conf

A quick method to verify the bridge without hardware board is using native_sim application. The samples/net/ethernet/bridge/bridge-test-setup.sh provides a script for host set-up. The steps are as below.

  1. Run script for pre-setup. Two tap interfaces zeth0 and zeth1 will be created.

bridge-test-setup.sh pre-setup
  1. Run native_sim application.

  2. Run script for post-setup. zeth1 will be moved to another net name space. (We couldn’t complete this post-setup before running native_sim application, because it seems zephyr iface will not connect interface in net name space.)

bridge-test-setup.sh post-setup
  1. Test the bridging between zeth0 and zeth1. The IP will be configured as below. Ping zeth1 in another net name space.

    • zeth0: IPv4 192.0.2.2, IPv6 2001:db8::2

    • zeth1: IPv4 192.0.2.3, IPv6 2001:db8::3

ping 192.0.2.3
ping 2001:db8::3
  1. Clean up after testing.

bridge-test-setup.sh clean

Spanning tree

The samples/net/ethernet/bridge/rstp.conf extra config file runs the Rapid Spanning Tree Protocol on the bridge. The bridge then blocks the ports that would make a loop, so its ports can be cabled in a ring with other bridges. The extra config file also gives the bridge a MAC address derived from the device ID, so that its Bridge Identifier stays the same across reboots.

west build -b mimxrt1170_evk@B/mimxrt1176/cm7 samples/net/ethernet/bridge -- -DEXTRA_CONF_FILE=rstp.conf
west flash

On the MIMXRT1170-EVK, the sample uses both Ethernet ports, the 100 Mb/s ENET and the 1 Gb/s ENET_1G, as bridge ports.

The net bridge stp shell command shows and sets the protocol. Without options it shows the bridge and its ports. The commands take interface indexes, which net iface lists:

uart:~$ net bridge stp 1
uart:~$ net bridge stp 1 --priority 4096 --max-age 20 --forward-delay 15
uart:~$ net bridge stp 1 port 2 --cost 20000 --link p2p
uart:~$ net bridge stp 1 --help

See also

Ethernet Support Functions
Network Interface abstraction layer