wiki:OpenWrt/swconfig

swconfig

swconfig is a lightweight Linux kernel driver API and a command-line tool that helps users configure ports on a managed switch to configure things like VLAN tagging. Note that you can also use uci, or write directly to /etc/config/network for a more permanent solution. This tool allows for an 'unmanaged' switch to become a 'managed' switch, allowing for things like VLAN tagging/untagging and individual port monitoring.

Note that swconfig is an OpenWrt kernel feature only and is not a part of mainline Linux (see the discussion here on why it has not been accepted). The switch architecture that has made it into mainline Linux is the Distributed Switch Architecture or DSA.

Capabilities of swconfig:

  • get/set a port VLAN id (TAG)
  • get/set VLAN port membership
  • get a port link status
  • get port statistics counters
  • reset switch
  • apply conifg to switch
  • based on generic Netlink infrastructure (easily extensible)
  • much smaller API than DSA and does not interfere with network stack packet flow, but rather focuses on the control path of managed switches

Because swconfig does not create a network interface per switch port, it can not support STP, LLDP, 802.1x, or other protocols that operate at a network device layer as the CPU can't send/receive packets to/from individual ports on the switch chip.

See also:

Usage

First thing a user should do is list out the devices currently available for swconfig to configure.

root@OpenWrt:/# swconfig list
Found: switch0 - mvsw6171

From this point on, you can list the current configuration of the switch, or show a list of options that the switch supports:

  • enable or disable a port:
    swconifg dev <switch> port <portno> set disable <0|1>
    
  • disable VLANs:
    swconfig dev <switch> set enable_vlan 0
    swconfig dev <switch> set apply
    

For example, OpenWrt running on a Ventana board with a GW16083 Ethernet expansion mezzanine:

root@OpenWrt:/# swconfig dev switch0 show
Global attributes:
        enable_vlan: 0
Port 0:
        mask: 0x0000: (0)
        qmode: 0
        pvid: 0
        link: port:0 link:down
Port 1:
        mask: 0x0000: (1)
        qmode: 0
        pvid: 0
        link: port:1 link:down
Port 2:
        mask: 0x0000: (2)
        qmode: 0
        pvid: 0
        link: port:2 link:up speed:1000baseT full-duplex
Port 3:
        mask: 0x0000: (3)
        qmode: 0
        pvid: 0
        link: port:3 link:down
Port 4:
        mask: 0x0000: (4)
        qmode: 0
        pvid: 0
        link: port:4 link:up speed:1000baseT full-duplex
Port 5:
        mask: 0x0000: (5)
        qmode: 0
        pvid: 0
        link: port:5 link:down
Port 6:
        mask: 0x0000: (6)
        qmode: 0
        pvid: 0
        link: port:6 link:down
root@OpenWrt:/# swconfig dev switch0 help
switch0: mvsw6171(MV88E6176), ports: 7 (cpu @ 4), vlans: 64
     --switch
        Attribute 1 (int): enable_vlan (Enable 802.1q VLAN support)
        Attribute 2 (none): apply (Activate changes in the hardware)
        Attribute 3 (none): reset (Reset the switch)
     --vlan
        Attribute 1 (int): port_based (Use port-based (non-802.1q) VLAN only)
        Attribute 2 (int): vid (Get/set VLAN ID)
        Attribute 3 (ports): ports (VLAN port mapping)
     --port
        Attribute 1 (string): mask (Port-based VLAN mask)
        Attribute 2 (int): qmode (802.1q mode: 0=off/1=fallback/2=check/3=secure)
        Attribute 3 (int): pvid (Primary VLAN ID)
        Attribute 4 (string): link (Get port link information)

In order to set values, you have to read the attribute, determine the information it requires and set it. For example, if you want to create a VLAN with an VID of 100, and add several ports to it, the following would be the appropriate way to accomplish this

root@OpenWrt:/# swconfig dev switch0 vlan 5 set vid 100
root@OpenWrt:/# swconfig dev switch0 vlan 5 set ports '2t 4'
root@OpenWrt:/# swconfig dev switch0 set enable_vlan 1
root@OpenWrt:/# swconfig dev switch0 set apply

The above example:

  1. Creates a VLAN (#5)
  2. Adds two ports to it (2t and 4) while adding tagging to the number '2' port (the 't' appended to the '2')
  3. Enables vlan's on this switch
  4. And finally applies the settings.

The result will look as follows:

root@OpenWrt:/# swconfig dev switch0 show
Global attributes:
        enable_vlan: 1
Port 0:
        mask: 0x0000: (0)
        qmode: 0
        pvid: 0
        link: port:0 link:down
Port 1:
        mask: 0x0000: (1)
        qmode: 0
        pvid: 0
        link: port:1 link:down
Port 2:
        mask: 0x0000: (2)
        qmode: 3
        pvid: 0
        link: port:2 link:up speed:1000baseT full-duplex
Port 3:
        mask: 0x0000: (3)
        qmode: 0
        pvid: 0
        link: port:3 link:down
Port 4:
        mask: 0x0000: (4)
        qmode: 3
        pvid: 100
        link: port:4 link:up speed:1000baseT full-duplex
Port 5:
        mask: 0x0000: (5)
        qmode: 0
        pvid: 0
        link: port:5 link:down
Port 6:
        mask: 0x0000: (6)
        qmode: 0
        pvid: 0
        link: port:6 link:down
VLAN 5:
        port_based: 0
        vid: 100
        ports: 2t 4

Please note that port 4 was added to the vlan due to it being the CPU port. One can determine this by running the following command

root@OpenWrt:/# swconfig dev switch0 help | grep "cpu @"
switch0: mvsw6171(MV88E6176), ports: 7 (cpu @ 4), vlans: 64

GW16083

The GW16083 is an Ethernet expansion mezzanine that is compatible with the Gateworks Ventana product family (if a mezzanine expansion is available on your board).

Note that the GW16083 support was added for swconfig in OpenWrt very recently in our latest OpenWrt on Github.

Note that the port numbers that swconfig are the physical ports on the MV88Ewith the GW16083 MV88E6176 chip. To map them to the silkscreen on the board use this table:

Please see GW16083 for a table of port mapping (matching silkscreen/connector to port numbers)

Last modified 7 years ago Last modified on 10/22/2017 05:28:45 AM
Note: See TracWiki for help on using the wiki.