The internal workings of a switch uplink port

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
Ok, i have been wondering this. I know switches only send packets to the port that the destination MAC address is connected to. (basically)

Heres my scenario:
Switch A
Switch B
Switch C
Switch D

A is uplinked to B, B is uplinked to C, etc.

Does A know what MAC addresses are on B? Basically, is an uplink port like a "hub" port or is it a "switched" port?
Or, is the uplink port like a default gateway, where if A doesnt know the MAC address it just sends it on the uplink port?

Basically, i want to know if B wants to send a packet to D, does it also goto A?

This might sound confusing, hopefully someone understands me. :)
 

Lord Evermore

Diamond Member
Oct 10, 1999
9,558
0
76
An uplink port is the same as every other port, it's just wired oppositely. An uplink port has the same pinout that a NIC port does, while a normal hub/switch port is wired the mirror way, send pin connecting to receive pin when using a straight-through cable. Basically it does what a crossover cable does between two NICs.

A switch uses a process known as "Flood, Learn, Forward".

When you uplink, the switch just sees the other switch as another "end-point". As an example, computer A1 on port 1 needs to connect to computer A2 on port 2 using a known IP address. (We'll assume that computer A1 already knows the MAC address of A2. Technically the first data sent would be the request for the MAC address of the computer with a certain IP.) The switch is receiving traffic for a certain MAC address, but doesn't know where it is. So it broadcasts (floods) to all the ports, just like a hub would. When computer A2 responds, the switch "learns" the MAC address is available on port 2. The switch also already learned that A1's MAC address is reachable via port 1. From now on, the traffic between them will be limited to those two ports, rather than broadcasting.

A switch doesn't exactly "see" each computer on each port. It doesn't have any clue what is physically on the other end. It only "learns" that when it needs to reach a certain MAC address, it will be reachable through a certain port so the traffic should go there.

Now, say A1 needs to talk to B2 on port 2 of Switch B. A1 sends out traffic. Switch A has no idea where the MAC address is, so it floods it to all the ports, including the uplink port to Switch B. Switch B receives the traffic, and doesn't know where B2 is located, so it floods all its ports as well (EXCEPT, it does not send the traffic to the port connected to Switch A, because it knows the traffic came from there in the first place). Now, B2 responds, and Switch B learns the MAC address, and it has already learned that the MAC of A1 is located on the port connected to Switch A. Now, when A1 sends to B2, Switch A will only forward packets to the uplink port, and switch B will only send to port 2; return traffic will only go from Switch B to the port connected to Switch A.

With the other switches, they've also received all the broadcasts sent from the other switches searching for a MAC address because none of the switches knew where the MAC was so they all forwarded the broadcast. They've now learned where computer A1 is located and which port they can send traffic to to reach it, so if computer D3 needs to reach A1, a broadcast is not needed at all. When D3 sends traffic, all the switches in between will ALSO learn where D3 is located, so they won't need to broadcast if C2 needs to reach D3. However, switch C and D did NOT learn the location of B2, because that computer did not have a broadcast of traffic reaching them; B2's response ONLY went to Switch A.

In short, when a switch is first connected and no traffic is sent, then yes, all the traffic is broadcast. But once a switch learns the location of a particular MAC address, it never needs to broadcast traffic for it again. It will only go to whichever port it has learned is where it can reach that MAC address.
 

MichaelD

Lifer
Jan 16, 2001
31,528
3
76
*tips hat*

Lord Evermore, that is one of the best-written, technical but easily-understood explanations I've ever read. I know how switches work, but now I have a much better understanding. Props to you for writing such a darn good tutorial!!!

This should be in the FAQ under "How Do Switches Work?" or words to that effect. Great job! *buys you a pint* you-->:D:beer:
 

MichaelD

Lifer
Jan 16, 2001
31,528
3
76
Really, where the heck did Lord Evermore's two replies go? The reply count for this thread indicates 7, but there aren't!
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
Hey! now i wanna know what happened to lord evermores post too, i didnt even get to see it. Very odd, b/c it says 8 replies and theres only 6. Anyways, thanks for the links.
 

Lord Evermore

Diamond Member
Oct 10, 1999
9,558
0
76
Originally posted by: Lord Evermore
An uplink port is the same as every other port, it's just wired oppositely. An uplink port has the same pinout that a NIC port does, while a normal hub/switch port is wired the mirror way, send pin connecting to receive pin when using a straight-through cable. Basically it does what a crossover cable does between two NICs.

A switch uses a process known as "Flood, Learn, Forward".

When you uplink, the switch just sees the other switch as another "end-point". As an example, computer A1 on port 1 needs to connect to computer A2 on port 2 using a known IP address. (We'll assume that computer A1 already knows the MAC address of A2. Technically the first data sent would be the request for the MAC address of the computer with a certain IP.) The switch is receiving traffic for a certain MAC address, but doesn't know where it is. So it broadcasts (floods) to all the ports, just like a hub would. When computer A2 responds, the switch "learns" the MAC address is available on port 2. The switch also already learned that A1's MAC address is reachable via port 1. From now on, the traffic between them will be limited to those two ports, rather than broadcasting.

A switch doesn't exactly "see" each computer on each port. It doesn't have any clue what is physically on the other end. It only "learns" that when it needs to reach a certain MAC address, it will be reachable through a certain port so the traffic should go there.

Now, say A1 needs to talk to B2 on port 2 of Switch B. A1 sends out traffic. Switch A has no idea where the MAC address is, so it floods it to all the ports, including the uplink port to Switch B. Switch B receives the traffic, and doesn't know where B2 is located, so it floods all its ports as well (EXCEPT, it does not send the traffic to the port connected to Switch A, because it knows the traffic came from there in the first place). Now, B2 responds, and Switch B learns the MAC address, and it has already learned that the MAC of A1 is located on the port connected to Switch A. Now, when A1 sends to B2, Switch A will only forward packets to the uplink port, and switch B will only send to port 2; return traffic will only go from Switch B to the port connected to Switch A.

With the other switches, they've also received all the broadcasts sent from the other switches searching for a MAC address because none of the switches knew where the MAC was so they all forwarded the broadcast. They've now learned where computer A1 is located and which port they can send traffic to to reach it, so if computer D3 needs to reach A1, a broadcast is not needed at all. When D3 sends traffic, all the switches in between will ALSO learn where D3 is located, so they won't need to broadcast if C2 needs to reach D3. However, switch C and D did NOT learn the location of B2, because that computer did not have a broadcast of traffic reaching them; B2's response ONLY went to Switch A.

In short, when a switch is first connected and no traffic is sent, then yes, all the traffic is broadcast. But once a switch learns the location of a particular MAC address, it never needs to broadcast traffic for it again. It will only go to whichever port it has learned is where it can reach that MAC address.


Don't know why anybody else can't see it. Are any posts of mine showing up? Maybe it was posted during a change to the code so only one server is carrying it?
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
Lord Evermore, i see your posts now! *phew*

You told me EXACTLY what I wanted to know. Thank you.
I also got bored and drew this up, tell me what you think of it and if the wording is correct (to see if i understand Flood, learn, forward).
Link
 

Lord Evermore

Diamond Member
Oct 10, 1999
9,558
0
76
Very nice.

First thing though, is that Tom isn't flooding the switch ports. Tom sends an ARP request asking "what MAC address is using this IP address?", which the switch itself then floods. Then the flood cascades to the other switches as well, and eventually Joe's machine responds with "I'm that IP address, here's my MAC address". In that process, the switches learn the MACs and which port they're reachable on. My original explanation assumed that each computer already knew the MAC address of the destination, but it works the same way, since the switches need to learn them as well, and in reality each computer wouldn't already know the MAC.

In the first section, switches C and D did learn where Tom is, because switch B flooded all ports, including the port connected to C, which also flooded all ports, including the port to D which flooded all of its ports too. C and D did not learn where Joe is though, since that only went to A.

Then that changes what happens in the other scenarios. Amy's computer has to send an ARP request for Tom's machine's IP (each computer received the ARP request Tom sent out earlier, but ignored it because Tom wasn't asking for them, it was asking for Joe). So the request gets flooded to all of D's ports, C's ports, B's ports, and A's ports. Now Tom's computer replies. All the switches have learned Amy's MAC now, and already knew where Tom was.

The switches themselves do NOT respond to any ARP requests or any other traffic. The learning and forwarding is ONLY so that the switch knows which port to send traffic to, based on the destination MAC. They also do NOT learn the exact location of the MAC. D does not know that Tom is on A, it only knows that it receives traffic from Tom through its own port 1, so if someone sends to Tom's MAC, it needs to send the traffic through port 1 and not some other port.

All the switches now know where Amy and Tom are, and switches A and B know where Joe is.

Now, Tim needs to send to Tom, so it does an ARP request which floods all the ports, and all the switches learn where Tim is. Tom responds, now Tim knows the MAC address for Tom.

Now we'll move on to the next thing. Now, all the switches know where Tim, Tom and Amy are. Only A and B know where Joe is.

Tim sends to Tom, and all the switches know where they both are, so they only send through the port that each switch knows is a path to Tom. Switch C doesn't know if Tom is on another switch, or on another network entirely, or connected directly to port 1. It only knows that it can reach Tom through port 1. So it passes up the chain directly to Tom.

Now, Tim needs to reach Joe. Assume for the moment that Tim does already know the MAC for Joe (maybe he was on the same switch at one point and now connects to C). Switch C doesn't know where he is, so it floods the traffic to all ports. Switch D receives and floods to all ports, and it dies on that end. Switch B receives it and knows Joe is reachable on port 3, so it does NOT send the traffic to switch A at all, it goes directly to Joe's port. Now Joe responds, and switch C learns his MAC, but switch D still doesn't know it.

Eventually when Joe or Amy need to communicate with each other, or Joe needs to start a connection to someone rather than only receiving connections, he'll end up broadcasting and D will learn his MAC.

You also don't have any uplink ports on those routers, only normal ports with crossover cables. :)