Before we understand the functions of a Network Switch , lets have a review of what a Network Switch is .
An Ethernet/Network Switch operates at the data link layer (layer 2) of the OSI model . Unlike a hub, a switch forwards a message to a specific host. When any host on the network or a switch sends a message to another host on the same network or same switch, the switch receives and decodes the frames to read the physical (MAC) address portion of the message.
An Ethernet switch creates separate collision domain for each switch port. Each device connected to a switch port can transfer data to any of the other ones at a time, and the transmissions will not interfere , with a caveat that in half duplex mode, each switch port can only either receive from or transmit to its connected device at a certain time. In full duplex mode, each switch port can simultaneously transmit and receive, assuming the connected device also supports full duplex mode.
Layer 2 switching is hardware based, it uses the host’s Media Access Control (MAC) address. Switches use Application Specific Integrated Circuits (ASIC) to build and maintain filter tables. Switches process faster than Routers, instead use the hardware address defined at the Data Link (MAC) layer to decide whether to forward or discard the frame unlike Router which works on Layer 3 and uses destination IP address for forwarding packets. Uses Layer 2 switching for network connectivity and network segmentation (each port is a separate collision domain).
There are three distinct functions of layer 2 switching are –
- Address Learning
- Forward/Filter decisions
- Loop Avoidance
1. ADDRESS LEARNING –
An Ethernet switch controls the transmission of frames between switch ports connected to Ethernet cables using the traffic forwarding rules described in the IEEE 802.1D bridging standard. Traffic forwarding is based on address learning. Switches make traffic forwarding decisions based on the 48-bit media access control (MAC) addresses used in LAN standards, including Ethernet.
To do this, the switch learns which devices, called stations in the standard, are on which segments of the network by looking at the source addresses in all of the frames it receives. When an Ethernet device sends a frame, it puts two addresses in the frame. These two addresses are the destination address of the device it is sending the frame to, and the source address, which is the address of the device sending the frame.
The way the switch “learns” is fairly simple. Like all Ethernet interfaces, every port on a switch has a unique factory-assigned MAC address. However, unlike a normal Ethernet device that accepts only frames addressed directed to it, the Ethernet interface located in each port of a switch runs in promiscuous mode. In this mode, the interface is programmed to receive all frames it sees on that port, not just the frames that are being sent to the MAC address of the Ethernet interface on that switch port.
As each frame is received on each port, the switching software looks at the source address of the frame and adds that source address to a table of addresses that the switch maintains. This is how the switch automatically discovers which stations are reachable on which ports.
Figure 1-2 shows a switch linking six Ethernet devices. For convenience, we’re using short numbers for station addresses, instead of actual 6-byte MAC addresses. As stations send traffic, the switch receives every frame sent and builds a table, more formally called a forwarding database, that shows which stations can be reached on which ports. After every station has transmitted at least one frame, the switch will end up with a forwarding database such as that shown in Table 1-1.
2. FORWARDING AND FILTERING –
Forwarding is the process of passing network traffic a device connected to one port of a Network Switch to another device connected to another port on the switch. When a Layer 2 Ethernet frame reaches a port on the Network Switch the switch reads the source MAC address of the Ethernet frame as a part of learning function, and it also reads the destination MAC address also as a part of forwarding function. The destination MAC address is important to determine the port number which the destination device is connected.
If the destination MAC address is found on the MAC address table, the switch forwards the Ethernet frame via the corresponding port of the MAC address.
If the destination MAC address is not found on the MAC address table, the switch forwards the Ethernet frame through all its ports except the source port. This is known as flooding. Normally flooding happens when the network switch is starting up. Flooding prevents loss of traffic when the switch is learning. When the destination device receives the Ethernet frame and send a reply frame to the source device, the switch reads the MAC address of the destination device and add it to the MAC address table, which is the function of learning process.
If the source MAC address is same as the destination MAC address, the switch will drop the Ethernet frame. This is known as filtering. This will normally happen if there is a hub connected to a port of the switch, and both the source device and destination device are connected to the hub.
3. LOOP AVOIDANCE –
In practical Local Area Networking, redundant links are created to avoid complete network failure in an event of failure in one link. Redundant links can cause layer 2 switching loops and broadcast storms. It is the function of a network switch to prevent layer 2 switching loops and broadcast storms.
Spanning Tree Protocol (STP) is used to stop network loops while still permitting redundancy
Spanning Tree Protocol is designed to perform port state transition to mitigate switching loops and allow the primary or preferred path active .The port states are as below –
Blocking – doesn’t forward any frames, but still listens to BPDUs. Ports default to blocking when the switch powers on. Used to prevent network loops. If a blocked port is to become the designated port, it will first enter listening state to ensure that it won’t create a loop once it goes into forwarding state.
Listening – listens to BPDUs to ensure no loops occur on the network before passing data frames.
Learning – learns MAC addresses and builds filter table, doesn’t forward frames.
Forwarding – sends and receives all data on the bridge ports. A forwarding port has been determined to have the lowest cost to the root bridge.