7

I am just wondering how a switch does know how to route packets to destinations "hidden" behind another switch. In my understanding a switch has a table that maps each of its hardware ports to exactly one MAC-address. So far so good, when a packet/frame (?) arrives it now can determine the port at which the packet should be routed.

But what happens when there is another switch connected to one of these ports and this second switch has more than one devices connected?

I am wondering how a switch is able to resolve this (on OSI-Layer 2, without a router), as I think this does indeed work in reality (?)

I am sorry if this question already exists (I think so, it should not be that uncommon), but I could not manage to put my thought into a suitable search query.

  • Related: How does a switch learn a switch table?. The same process by which one switch populates its MAC address table is used when there are two switches, or three switches, or any number of switches. – Eddie Apr 20 '16 at 14:27
14

A Layer 2 switch learns most of its information about the location of other endpoints via "listening" to ingressing frames, and when it is not aware of the location, it uses floodingand will learn from the answer. Lets say the topology is:

(Host A) <--> (Switch A) <--> (Switch B) <-->(Host B).

Also important to note, a L2 Switch forwards, it does not route. By that I mean, when it receives an encapsulated frame, it forwards it out interfaces.

  • Host A wants to get to Host B. Host A knows Host B's MAC address. So Host A sends a frame out to Switch A.
  • Switch A does not have Host B in its MAC address Table. Switch A then flood out the frame on all of its ports, except for the one Host A is located. Among all those ports there is the ports that Switch B is plugged into, so Switch B receives the frame.
  • Switch B then flood that frame out all of its ports (considering Switch B does not have Host B in its MAC address Table).
  • Host B will respond to the frame, Switch B will then record Host B MAC address and send the response to Switch A. Switch A then records the MAC address of Host B in its table and send the response to Host A

Here's a related question: How does a switch learn a switch table?

  • great, thanks! I thought about broadcasting, but thought it would add too much overhead, especially when many switches are chained together. – Jonas Eschmann Aug 25 '15 at 14:09
  • 2
    @sh4kesbeer It may be the case that the switches do not even generate "extra" L2 broadcasts: Before host A sends a packet to host B, it will typically send an arp request broadcast anyway asking for the MAC address belonging for the given IP address. Whyile processing that query, all switches learn from where the A's MAC enters. Hence they can already direct the arp reply correctly and (at least those along the path from B to A) learn where B's MAC enters from. - So "extra" broadcasting caused by the switch will typically occur only after a topology change – Hagen von Eitzen Aug 25 '15 at 17:39
  • This is not totally exact and could cause confusion. When the switch doesn't know on which port the destination host resides, it does FLOOD the frame on all ports (excepting the originating one), not broadcast. The frame is still an unicast frame being flooded on all ports, and not a broadcast. – JFL Apr 20 '16 at 9:16
4

The switch can map multiple mac-addresses to a port.

Thus all the device mac's on the second switch is seen by the first switch as belonging to one port.

It updates it's table when it receives any packet, as they all contain a source mac. If it had the mac on a different port before it changes it's mac address table (mac to port map).

When the position of a mac changes between ports often, it is reported as a mac flap.

1

When the topology is as described : Host A - Switch A - Switch B - Host B

Ideally, Host A will know the IP address of Host B (the destination that it wants to communicate to). Assuming the IP addresses of the two Hosts are in the same network, Host A uses ARP to get the mac address of the destination. This is a broadcast frame that is forwarded out the ports of Switch A - and Switch B - to Host B, which sees it is the intended recipient and replies with its own MAC address.

Host A later uses this MAC address and send the packet to Switch A.

Switch A sees the MAC address and forwards this packet out of the interface appropriate by referring to its own MAC table. Similar operation occurs at Switch B - that later reached the destination Host B.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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