0

Trying to think about this from a hardware design perspective, if I had to design an FPGA or a uC or something to manage a single port being the gateway port and one or more switched ports for routing, with the guarantee that one port == one neighbor and thus one MAC address to route, then it'd be as simple as storing a single MAC address for each port in the firmware's memory and switching/dropping packets based on which MACs I know of.

However, how does it work when there is an arbitrary number of 'neighbors' downstream from a port, i.e. when a port is connected to another layer 2 switch? Would I theoretically have to keep a whole list of known neighbors at that port? That means some arbitrary limit of downstream nodes I could keep track of. Since MACs are not prefixed-based (like IP addresses are), doing the typical CIDR masking wouldn't be sufficient.

Further, if it was just a catch-all "forward packets destined for any unknown MAC to the next hop", then it'd mean potentially flooding all ports with any unknown packets, wouldn't it?

How does this work in reality? Is there something obvious I'm missing with how layer 2 switching works in such a topology?

5
  • I realize this is probably already answered extensively on the internet somewhere but my google-fu wasn't good enough to find much about how the routing actually works based on MAC and multiple hops involved. Any terminology/search terms here would be helpful! Commented Aug 7, 2023 at 9:22
  • "How do layer 2 switches route based on MAC..." Layer-2 switches do not route. Routing is at layer-3, and layer-2 frame headers (including those containing MAC addresses) are stripped off the layer-3 packets before the packets are routed.
    – Ron Maupin
    Commented Aug 7, 2023 at 13:09
  • I'm quite certain that despite the specific terminology used, that the underlying meaning is still clear :) The answer here perfectly understood the question. Commented Aug 14, 2023 at 23:02
  • I did understand, but you should use the correct terminology when asking questions. Routers route, bridges bridge. Layer-2 switches are bridges. Both can be said to forward traffic. Routers forward packets, and bridges forward frames. See this answer and this answer about that.
    – Ron Maupin
    Commented Aug 14, 2023 at 23:30
  • Yes, thank you. I see my mistake now and won't do it again. Commented Aug 18, 2023 at 7:15

1 Answer 1

2

Switches are self-learning bridges: they inspect each incoming frame for its source MAC address and store that address with the ingress port in their source-address or MAC table.

Any MAC address can only be associated with a single port, but each port can be associated with any number of MAC addresses (except for really ancient switches), up to the maximum supported number.

On hardware switches, the MAC table is implemented using content-addressable memory (CAM), so that the port association is located in a single lookup step.

When a frame is received on any port, its source MAC address is used to update the MAC table. Its destination address is looked up in the MAC table and the frame is forwarded out the port indicated by the table entry. If the address cannot be found the switch mimics a repeater hub and floods the frame out of all ports but the ingress one.

with the guarantee that one port == one neighbor

That is an assumption only true for edge ports, and not normally taken by any switch in its default configuration.

Accordingly, you can connect switches any which way - a chain, a tree, or even in a ring when you provide means to avoid the resulting bridge loop (most commonly a spanning tree protocol).

Technically, a tree is usually the most efficient and resilient way to connect Ethernet switches.

enter image description here

https://www.ciscopress.com/articles/article.asp?p=2202410&seqNum=4

3
  • Thanks! Very informative. One question though, when you say that the addresses are content-addressable, do you mean that they're e.g. hashed or something? Because (2^(6*8))*(6*8) bits = 1.689 PB of memory if done linearly. If so, isn't there a chance for hash collisions? Or are they instead looked up using a binary search or something like that? Commented Aug 7, 2023 at 10:00
  • 1
    No hash, no search - the memory is addressable by content in addition to by address: en.wikipedia.org/wiki/Content-addressable_memory
    – Zac67
    Commented Aug 7, 2023 at 10:02
  • Ah it's a hardware approach to the problem. Neat, thanks! Commented Aug 7, 2023 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.