Manual:Switch Chip Features
In this topic we will talk about switch chip features that are implemented in RouterOS (complete set of features implemented starting from v3.32 and v4.0)
Presently we use several types of switch chips on our Routerboards and they have a different set of features. Most of them (from now on "Other") have only basic "port switching" feature, but there are few with more features - full table below:
Capabilities of switch chips:
|Host table||2k entries||2k entries||no||no|
|Vlan table||4096 entries||16 entires||no||no|
|Rule table||32 rules||no||no||no|
Atheros8316 is present on RB450G.
Atheros7240 is present on RB750.
ICPlus175D is present on some RB450.
Command line config is under "/interface ethernet switch" menu. This menu contains a list of all switch chips present in system, and some sub-menus as well. "/interface ethernet switch" menu list item represents a switch chip in system:
[admin@MikroTik] /interface ethernet switch> print Flags: I - invalid # NAME TYPE MIRROR-SOURCE MIRROR-TARGET 0 switch1 Atheros-8316 ether2 none
Depending on switch type there might be available or not available some configuration capabilities.
Switching feature allows wire speed traffic passing among a group of ports, like the ports were a regular ethernet switch. You configure this feature by setting a "master-port" property to one ore more ports in "/interface ethernet" menu. A 'master' port will be the port through which the RouterOS will communicate to all ports in the group. Interfaces for which the 'master' port is specified become inactive - no traffic is received on them and no traffic can be sent out.
For example consider a router with five ethernet interfaces:
[admin@MikroTik] > interface ethernet print Flags: X - disabled, R - running, S - slave # NAME MTU MAC-ADDRESS ARP MASTER-PORT SWITCH 0 R ether1 1500 00:0C:42:3E:5D:BB enabled 1 ether2 1500 00:0C:42:3E:5D:BC enabled none switch1 2 ether3 1500 00:0C:42:3E:5D:BD enabled none switch1 3 ether4 1500 00:0C:42:3E:5D:BE enabled none switch1 4 R ether5 1500 00:0C:42:3E:5D:BF enabled none switch1
And you configure a switch containing three ports ether3, ether4 and ether5:
[admin@MikroTik] /interface ethernet> set ether4,ether5 master-port=ether3 [admin@MikroTik] /interface ethernet> print Flags: X - disabled, R - running, S - slave # NAME MTU MAC-ADDRESS ARP MASTER-PORT SWITCH 0 R ether1 1500 00:0C:42:3E:5D:BB enabled 1 ether2 1500 00:0C:42:3E:5D:BC enabled none switch1 2 R ether3 1500 00:0C:42:3E:5D:BD enabled none switch1 3 S ether4 1500 00:0C:42:3E:5D:BE enabled ether3 switch1 4 RS ether5 1500 00:0C:42:3E:5D:BF enabled ether3 switch1
ether3 is now the master port of the group. Note: you can see that previously a link was detected only on ether5, but now as the ether3 is a 'master' the running flag is propagated to master port.
/----- RouterBoard ----------------------------------------------------\ | | | routing, bridging, fw, qos, etc. | | ******************************* | | | | | | | | | ether3 | | | | | wire-speed switching | | | | +---------------+---------------| | | | | | | | | | ether1 ether2 ether3 ether4 ether5 | | | | | | | | \-- | ---------- | ----------- | ---------- | ----------- | --/
In essence this configuration is the same as if you had a RouterBoard with 3 ethernet interfaces with ether3 connected to ethernet switch that has 4 ports:
/----- RouterBoard -----------------------\ | routing, bridging, fw, qos, etc. | | ******************************* | | | | | | | ether1 ether2 ether3 | | | | | | \-- | ---------- | ----------- | -----/
| | | | | /----- | -- Ethernet switch ---\ | | | p1 (cpu port) | | | | | | | | | +-------+--------\ | | | | | | | | | | | p2 p3 p4 | | | | | | | | | | \----- | ---- | ---- | ------/ | | | | |
A more genereal diagram of RouterBoard with switch chip that has 5 port switch chip:
/----- RouterBoard ----------------------------------------------------\ | | | RouterOS - routing, bridging, fw, qos, etc. | | *************************************************************** | | | | | | | | | | | | | | | | | | | | | | | switch logic | | |-------------+---------------+---------------+---------------| | | | | | | | | | ether1 ether2 ether3 ether4 ether5 | | | | | | | | \-- | ---------- | ----------- | ---------- | ----------- | --/
Here you can see that, a packet that gets received by one of the ports always passes through the switch logic at first. Switch logic decides to which ports the packet should be going to. Passing packet 'up' or giving it to RouterOS is also called sending it to switch chips 'cpu' port. That means that at the point switch forwards the packet to cpu port the packet starts to get processed by RouterOS as some interfaces incoming packet. While the packet does not have to go to cpu port it is handled entirely by switch logic and does not require any cpu cycles and happen at wire speed for any frame size.
Port mirroring lets switch 'sniff' all traffic that is going in and out of one port (mirror-source) and send a copy of those packets out of some other port (mirror-target). This feature can be used to easily set up a 'tap' device that receives all traffic that goes in/out of some specific port. Note that mirror-source and mirror-target ports have to belong to same switch. (See which port belong to which switch in "/interface ethernet switch port" menu). Also mirror-target can have a special 'cpu' value, which means that 'sniffed' packets should be sent out of switch chips cpu port. Port mirroring happens independently of switching groups that have or have not been set up.
Basically the table represents switch chips internal mac address to port mapping. It can contain two kinds of entries: dynamic and static. Dynamic entries get added automatically, this is also called a learning process: when switch chip receives a packet from certain port, it adds the packets source mac address X and port it received the packet from to host table, so when a packet comes in with destination mac address X it knows to which port it should forward the packet. If the destination mac address is not present in host table then it forwards the packet to all ports in the group. Dynamic entries take about 5 minutes to time out. Learning is enabled only on ports that are configured as part of switch group. So you won't see dynamic entries if you have not specified some 'master-ports'. Also you can add static entries that take over dynamic if dynamic entry with same mac-address already exists. Also by adding a static entry you get access to some more functionality that is controlled via following params:
copy-to-cpu=yes/no - a packet can be cloned and sent to cpu port redirect-to-cpu=yes/no - a packet can be redirected to cpu port mirror=yes/no - a packet can be cloned and sent to mirror-target port configured in "/interface ethernet switch" drop=yes/no - a packet with certain mac address coming from certain ports can be dropped
copy-to-cpu, redirect-to-cpu, mirror actions are performed for packets which destination mac matches mac address specified in entry drop action is performed for packets which source mac address matches mac address specified in entry
Another possibility for static entries is that mac address can be mapped to more that one port, including 'cpu' port.
Vlan tables specifies certain forwarding rules for packets that have specific 802.1q tag. Those rules are of higher priority than switch groups configured using 'master-port' property. Basically the table contains entries that map specific vlan tag ids to a group of one or more ports. Packets with vlan tags leave switch chip through one or more ports that are set in corresponding table entry. The exact logic that controls how packets with vlan tags are treated is controlled by vlan-mode parameter that is changeable per switch port in "/interface ethernet switch port" menu. vlan-mode can take following values:
disabled - ignore vlan table, treat packet with vlan tags just as if they did not contain a vlan tag; fallback - the default mode - handle packets with vlan tag that is not present in vlan table just like packets without vlan tag. Packets with vlan tags that are present in vlan table, but incoming port does not match any port in vlan table entry does not get dropped. check - drop packets with vlan tag that is not present in vlan table. Packets with vlan tags that are present in vlan table, but incoming port does not match any port in vlan table entry does not get dropped. secure - drop packets with vlan tag that is not present in vlan table. Packets with vlan tags that are present in vlan table, but incoming port does not match any port in vlan table entry get dropped.
Vlan tag id based forwarding also take into account the mac addresses learned or manually added in host table.
Rule table is very powerful tool allowing wire speed packet filtering, forwarding and vlan tagging based on L2,L3,L4 protocol header field matchers.
Each rule contains a matching part and an action part. Action part is controlled by following parameters:
copy-to-cpu=yes/no - clones matching packets and sends them to cpu port; redirect-to-cpu=yes/no - redirects matching packets to cpy port; mirror=yes/no - clones matching packets and send them to mirror-target port; new-dst-ports - if set forces the destination port to be as specified, multiple ports allowed, including cpu port. Non obvious feature of this parameter is to pass empty list of ports to drop matching packets; new-vlan-id - if specified changes the vlan tag id, or add new vlan tag if one was not present; new-vlan-priority - if specified changes the vlan tag priority bits;
Matching part is controlled by rest of parameters:
ports - match port that packet came in from (multiple ports allowed);
// mac layer matchers dst-mac-address - match by destination mac address and mask; src-mac-address - ...; vlan-header - match by vlan header presence; vlan-id - match by vlan tag id; vlan-priority - match by priority in vlan tag; mac-protocol - match by mac protocol (skips vlan tags if any);
// ip matchers dst-address - match by destination ip and mask; src-address - match by source ip and mask; dscp - match by ip dscp field; protocol - match by ip protocol;
// ipv6 matchers dst-address6 - match by destination ip and mask; src-address6 - match by source ip and mask; flow-label - match by ipv6 flow label; traffic-class - match by ipv6 traffic class; protocol - match by ip protocol;
// L4 matchers src-port - match by tcp/udp source port range; dst-port - match by tcp/udp destination port range;
IPv4 and IPv6 specific matchers cannot be present in same rule. Menu contains ordered list of rules just like in "/ip firewall filter". Due to the fact that the rule table is processed entirely in switch chips hardware there is limitation to how many rules you may have. Depending on the amount of matchers you use in your rules the amount of active rules may vary from 8 to 32 for Atheros8316 switch chip. You can always do "/interface ethernet switch rule print" after modifying your rule set to see that no rules at the end of the list are 'invalid' which means those rules did not fit into the switch chip.