Networking Primer – Part 6.3: Layer 2 Switching – Loops, Spanning Tree and Topologies

Previous: Networking Primer – Part 6.2: Media Access Control – CSMA/CD, CSMA/CA

We were briefly introduced to devices called Network Switches in the last post in this series. A switch essentially acts as a central connection point in a star topology  for many network nodes.It is similar to a Hub from a topological perspective but whereas a hub will take a frame in from one port and broadcast it out on all of the other ports, a switch has some built-in intelligence so it may forward the frame only to those ports which should receive the frame.  I like to think of a switch very much like it’s similar namesake, the switchboard, from the public telephony world.

Old Telephony Switchboard

In this older world, you picked up your phone to call the operator.  When the operator at the other end answered, you would tell her/him who you would like to call, they would cross reference the name with the relevant port number on the switchboard and plug in a cross-connecting wire between your incoming port to your outgoing call recipients. A network switch operates in a similar fashion although there are of course some notable differences.

Switch Ports

Ports are a very important entity in the switching process. Modern switches can contain 8, 16, 24 .. or even 1000’s of ports in large-scale enterprise level implementations. Port occupancy on a network switch can be very transient with desktops and laptops changing the port they are plugged into on a daily basis. To cope with this, the switch must be much more malleable and must have a mechanism for learning which device is occupying which port. It does this by maintaining a table of the source MAC addresses it receives from each port.  It is worth being aware that if a switch doesn’t know which port of the destination MAC address it will still broadcast to all the other ports in the same way a hub does.

I can’t emphasise the following enough, so it is worth re-iterating.. the Port is a very important entity in the switching process and is not only a node’s physical access point into the network.  It also represents a management construct that can be used to control the nodes security and resource permissions within the network.  The Port and it’s associated ID can be used to segment traffic as well as shape it (e,g, restrict bandwidth, etc).

Switching Topologies

A single switch device connecting all the nodes in a network is a pretty simple architecture to visualise and understand. This kind of set-up is however only found in small office environments. In larger environments, it may become impossible to cable all of the nodes into the same switch due to geographical, redundancy or resiliency factors.  In these environments, we need to introduce multiple interconnected switches.  Luckily most modern switches have the intelligence to connect to other switches in pretty much any configuration. We can daisy chain them together, make circular loops or any other artistic creation we wish.. all of these are possible:

Logical Topologies

When a switch is connected to another switch, it soon learns that the interconnecting port isn’t occupied by a single node and MAC address. They’ll learn that there is another switch there and that the port is possibly the destination for many devices. Any source MAC addresses coming in from that port will be stored in the table so that local nodes may send frames back to those devices via that port.  Given this flexibility, of connecting switches together in any configuration, it is possible to find ourselves with the problem of circular switching loops.

Switching Loops and the Spanning Tree Protocol

As stated above, if a switch receives a frame on a port and hasn’t yet learned the forwarding port of its MAC Address, it will broadcast it out on all of its ports with the exception of the one it receives it from. This is called a broadcast of an unknown unicast frame. A similar bulk multi-port forwarding operation may occur for general broadcast frames as well as multicast frames (frames for more than one destination node).  These multi-port broadcast have the potential to turn into infinite circular loops where there is a circular route to follow in an architecture.

Take the following example:

Switching Loops

A node connected to Switch B wants to communicate with a node connected to Switch C. It doesn’t know where the forwarding port for this node is so Switch B broadcasts to all ports including the ports interconnecting A, C, D & E. Switch A will send it to C, D & E. The frame will reach its destination on Switch C, but it may receive two copies of the frame, one from B one from A. Also now that D is in the mix, it’s possible D could broadcast it back to B, who in turn will broadcast it back to A. This is just one example of a switching loop.

The problem with these loops is that they’re often difficult to spot. The frame does get where it’s going, but multiple copies of it are being looped. This is only really apparent when the switches CPU seems to be increasing workload for no apparent reason. Enter STP or Spanning Tree Protocol. In Brief, STP learns the multiple possible routes a frame may take across the switching infrastructure. It then assesses these multiple routes using an algorithm to select the best one and blocks the rest, thus preventing any looping.

The Hierarchical Network Model

The Hierarchical Network Model is a network design model created by Cisco. It’s a very simple layered model created from medium or large network environments. The Layers are defined as follows:

  • Core Layer – composed of powerful high throughput switches and border routers to make up the backbone of the network
  • Distribution layer – a second tier layer used for aggregation the lower layer switches and connecting through to core.
  • Access Layer – the tier containing the front-end switches where the network devices/nodes gain access to the network.

The Hierarchy Network Model


This model is very widely deployed and has become somewhat of a defacto standard. It is worth remembering these layers and where they sit. In future blogs, I intend to address network virtualization and how it has shifted the dotted line and pulled some of the access layer into the hypervisor (more to come on this later).

 Next: Part 6.4: VLANs and other ANs (Area Networks)

Networking Primer – Part 6.2: Media Access Control – CSMA/CD, CSMA/CA

Previous: Networking Primer – Part 6.1: Data Link Layer, Ethernet and MAC

I will start this post with a foreword that at least one of the protocols in the title, CSMA/CD, is obsolete. I’m including it here as it’s very useful to understand why we no longer need it, due to the changes in layer 2 topologies that have evolved over time. A little history can illuminate why we are where we are.

CSMA (Carrier Sense Multiple Access) is a methodology that deals with multiple computing nodes access the same physical media, whether that be a piece of wire, optical fibre or even the air.  It makes sense that there should be some rules around when each node can transmit/receive rather than a free-for-all where interference, possible corruption and inefficiency can occur. The media is being shared so access needs to be given through arbitration.

There are two sub-methodologies for CSMA. These being CSMA/CD (Collision Detection) and CSMA/CA (Collision Avoidance).

CSMA/CD history

As mentioned in the previous post, initially Ethernet systems were based on coax (coaxial cable). Networks were implemented in a bus sharing topology. All of the nodes in the network would share the same piece of coax and essentially have their NIC connected to a piece of coax that was piped directly into the main bus coax via a T-Bar connector, that looked like this:

Coax T-Bar

You can see a typical network bus topology here:

LAN Bus Topology

In order to ensure communication between the nodes could occur. CSMA/CD was used. In CSMA/CD, each node would step through a process to get the desired result. The process was as simple as:

  1. Listen to see if the wire is idle.
  2. If idle, transmit the data.
  3. If a collision occurred with another node transmission, wait a random period of time then try again.

In this topology, we have to be aware that the wire represents what we call a “collision domain”. While using a single collision domain (i.e. wire) was reasonably efficient for a small number of computers, it had many problems with reliability and scale. From a reliability perspective, if there was a break anywhere in the wire, it would take down the whole domain. Another common problem was the absence of or faulty terminators (labelled Terminating resistor above).  Without a functioning terminator on the end of the coax, the bus wouldn’t function. A secondary issue here was scale. The more nodes you added, the more collisions you’d see and the less well the network would function.

There were several approached developed to mitigate these issues, revolving around the idea of breaking networks down into smaller segments and therefore smaller collision domains.

Network Hubs

The coax bus topology was soon dumped in favour of using Twisted Pair (TP) cabling and a star/mesh based topology. In order to move away from the single wire bus topology, a new device needed to be introduced to act as the central connection point for the network, as each node would now have it’s own wire. Enter the hub. A hub is essentially a box with a bunch of ports on it. Each node can be plugged into a separate port on the using it’s own TP cable that has an RJ45 connector on each end. Using a star topology, with our nodes sitting on spokes around our hub, does resolve some of our reliability problems. If a wire breaks or is faulty, only the node sitting at the end of it is affected and not the whole network.

Hub Topology

The hub is, however, a very dumb piece of equipment. It takes frames in on any single port and then sends those frames out to every other port. From a collision perspective we still only have a single collision domain. This means that we still have to use CSMA/CD and we still have problems with scaling.

 Network Bridges

A network bridge is an additional network device that has a little more intelligence, but only a small step up from a hub. A bridge only has two ports, it sits between two network segments and learns which mac addresses sit on either side of it. If it sees a destination MAC address coming in from side A, and it knows that the destination node is on side A, it will drop the frame. Therefore, none of the nodes on side B will ever see it. We have reduced our network traffic by 50% on each side and also halved our collision domain.

Network Bridge


Network Switches

While Hubs and Bridges made significant strides in improving both reliability and reducing collision domains, it was clear that scale and management were still difficult for any network that was larger than a few 10’s of nodes. The network needed additional intelligence.  That intelligence came in the form of “Switching” and the new device to do that was the “Network Switch”.

The switch takes things much, much further. A switch has more than two ports, topologically it can be used instead of a hub. In the same way as they do to a hub, each of the nodes connects directly into the switch on a port. The switch is able to do the same sort of filtering that a bridge does, but it can do that on a per port basis. Rather than separating two network segments like a bridge, the switch is separating each and every node. When a frame comes in on one port, the switch is intelligent enough to send it out only on the port (or ports) where it needs to go to, to reach its destination. It has the intelligence to learn which MAC Addresses are sitting on which ports and updates its own internal tables as this changes.

Circling back to our title, bus using a switch we have effectively reduce our collision domain to a single wire per node. We therefore no longer need a methodology to arbitrate access to the media. Hence the obsolescence of CMSA/CD.

This is as deep as we’ll go on switching until the next post.

CMSA/CA – Carrier Sense Multiple Access – Collision Avoidance

CSMA/CD is very much the bull in a china shop, feet first approach to accessing physical media. CSMA/CA represents a more cautious approach with the goal of avoiding any collisions in the first place. It is still relevant and prevalent today due to the nature of WiFi networks.

In a WiFi network, the physical media is essentially the air (or radio waves running through it). As you can imagine, it would be very difficult to segment air in the same way as a wired network as there are no clear points in ingress/egress. We could try to use the CSMA/CD approach, but this isn’t effective in WiFi as each node communicates directly with the wireless AP (Access Point) and not with each other. This is called the hidden node problem, where collisions can’t be detected so the node never knows one has occurred. By using CSMA/CA, the WiFi network is able to work around the issue. With this methodology the AP mediates access to the media. A node requests permission to send, the AP gives the node a CTS (Clear To Send) acknowledgement and the node will send its entire payload across the channel. Only one node at a time has access to the channel.

Now we have successfully accessed or media and pushed our frame out of the source node, let’s look at how that’s moved across the LAN.

Next: Networking Primer – Part 6.3: Layer 2 Switching – Loops, Spanning Tree and Topologies

Networking Primer – Part 6.1: Data Link Layer, Ethernet and MAC

Previous:Networking Primer – Part 5.3: Network Layer – IP Routing

In previous posts we’ve covered logical addressing and moving IP packets of data across our network from source to destination. We’re now going to take a further shift towards the bits and bytes details of how that logical addressing and routing relates to the more tangible physical media that is used to transmit the data.  This is where the Data Link Layer becomes applicable.  “The Data Link Layer” is a bit of a mouthful, so this is often dropped and the OSI stack layer number is substituted, Layer 2. From this point forward I will use “Data Link Layer” and “Layer 2” as interchangeable terms which mean exactly the same thing.

The Data Link Layer breaks down into two sub-layers. Firstly, we have the upper sub-layer, called Logical Link Control (LLC) and beneath it we have the Media Access Control Layer.  The LLC Layer is responsible for establishing links (connections) between devices in the same local area. It also includes some error checking and handling. The MAC Layer encapsulates a set of protocols and rules for how those devices will gain access to the physical media in order to transmit/receive data.

Historically, there have been a number of competing protocols and topologies used at this layer.  In the 80’s and later Ethernet, FDDI and Token Ring approaches were all vying to become the standard for LAN (Local Area Network) traffic, but unquestionably due to its flexibility and reduced cost, Ethernet has won that battle.  Most LANs are built on Ethernet today, although more recently with the rise of mobile devices, it has become a shoulder to shoulder partner with the WLAN (Wireless LAN) which provides WiFi access to networks.


Ethernet is predicated on the concept of giving network nodes access to a shared physical media, where all nodes in the network can either send or receive data. In its original incarnation, coax (coaxial cable) was used as Ethernet’s shared physical media combined with a Bus topology. As more and more devices were added to the network, the coax based approach did not scale well and became difficult retain reliable service. The coax approach was superseded by the use non-shared physical media interconnected via network devices which we have yet to introduce such as Hubs, Bridges and Switches.  Before we get to the topologies we should look some of the other functions and terminology.

As with our upper layers, when the data is passed down to this layer we add another additional outer wrapper that includes all of the relevant metadata we need to work with Layer 2 functions. We are effectively adding some header information and may also break down our data further if that is required by the underlying devices. In the network layer, we have so far referred to our chunks of data as Packets (IP Packets), at this layer we refer to our chunks of data as Frames (Ethernet Frames). To re-iterate the clear distinction here: Network Layer = Packets, Data Link Layer = Frames. This is useful terminology to get clear.

We’re ready to send our frame out onto the physical media but how will the other nodes know whether or not they’re the intended recipient? Answer, MAC addressing.

MAC Addresses

IP Addresses are a logical constructs that can be allocated, de-allocated, moved and re-used. To physically tie our node to the network, IP addresses are not used. We have a different addressing mechanism at Layer 2, this is the MAC (Media Access Control) Address.  The physical component that interacts with the network from our node is the NIC (Network Interface Card). Historically, at the time of manufacture each NIC was allocated a unique MAC Address from a world-wide pool, so it could be differentiated on any network. The MAC Address is a 48-bit address that is most commonly displayed in hexadecimal format (e.g. 28:CF:E9:1F:B4:79). While it is not as humanly readable as an IP address is, it’s still a better representation than the underlying 48 0’s and 1’s that we’d have to remember without it.  Do the following to check your local MAC Address:

When our frame leaves our node via our NIC onto the shared media, the layer 2 wrapper includes both a source and destination MAC Address.  This is all good but there’s a problem we have missed here, we know the destination IP address, but where did we get the destination MAC address from? Well there isn’t a DNS style server that stores and provides this. As the nodes are all on the same physical media (sometimes referred to as “broadcast domain”) we can simply ask all the nodes, but we need some protocols to do that. This is where ARP (Address Resolution Protocol) joins the party.

ARP (Address Resolution Protocol)

ARP is simply a mechanism for finding and storing relationships between IP and MAC addresses.

Each node retains a local ARP table/cache which lists relationships between IP and MAC Addresses. When a frame is being sent, the sender cross references the IP address with its local ARP cache. If the IP/MAC combination isn’t listed, an ARP request is broadcast to all nodes on the network to find it. In plain English, the source node is asking “What’s the MAC for this IP address I have?”. All nodes pick this request up, and if they are the intended node, they’ll reply with a “That’s me and here’s my MAC address.” response. The response is cached for future reference.

Side note: There is also a protocol called RARP (Reverse Address Resolution Protocol) which does exactly the opposite. It was used so that nodes could find their own IP address, if they only knew their MAC. This protocol is now obsolete and has since been superseded BOOTP which was in turn superseded by DHCP functionality.

 In the same way that we can use IPCONFIG/IFCONFIG to display, alter IP configurations, we can use the ARP command to view, manipulate the ARP cache. Examples here:

The ARP cache is not always up to date, especially where IP address changes might be frequent, so it is worth familiarizing yourself with the ARP switch commands that are used to directly manipulate the cache during troubleshooting. For instance, “ARP -D” can be used to delete entries. There are also mechanisms for flushing the whole table.

Now we have all of our layer 2 addressing sorted, our frame is ready to go.

Next: Networking Primer – Part 6.2: Media Access Control – CSMA/CD, CSMA/CA