Sub topic 2
Unicast, broadcast and multicast destinations
This chapter assumes you know what a MAC address is, how it differs from an IP address, and that an Ethernet frame carries a destination MAC, a source MAC and an EtherType. Here you learn how a switch classifies the destination address, because that decision determines whether the MAC address table is consulted at all.
Three kinds of destination
Every destination MAC address is one of three types:
- Unicast: the frame is meant for one interface.
- Broadcast: the frame is meant for every interface on the local network. The address is
ff:ff:ff:ff:ff:ff. - Multicast: the frame is meant for a group of interfaces that chose to listen. Examples are
01:00:5e:00:00:fb(IPv4 mDNS) and33:33:00:00:00:01(all IPv6 nodes).
A switch does not need a configured list of these types. It reads one bit.
The group bit
The least significant bit of the first octet is called the individual/group bit. If it is 0, the address is unicast. If it is 1, the address is a group address. Broadcast and multicast are both group addresses.
| First octet | Binary | Last bit | Type |
|---|---|---|---|
| `00` | 00000000 | 0 | Unicast |
| `0a` | 00001010 | 0 | Unicast |
| `01` | 00000001 | 1 | Multicast |
| `33` | 00110011 | 1 | Multicast |
| `ff` | 11111111 | 1 | Broadcast (all bits set) |
Broadcast is a special case of a group address: all 48 bits are 1.
The is_group function in the switch code from this tutorial's later chapters applies this test.
def classify(mac):
first_octet = int(mac.split(':')[0], 16)
if mac.lower() == 'ff:ff:ff:ff:ff:ff':
return 'broadcast'
if first_octet & 1:
return 'multicast'
return 'unicast'
for address in ['00:00:00:00:00:0a',
'ff:ff:ff:ff:ff:ff',
'01:00:5e:00:00:fb',
'33:33:00:00:00:01']:
print(address, classify(address))Running it prints:
00:00:00:00:00:0a unicast
ff:ff:ff:ff:ff:ff broadcast
01:00:5e:00:00:fb multicast
33:33:00:00:00:01 multicastWhy the type matters to the switch
The type of the destination decides how the switch treats the frame.
- A unicast destination is looked up in the MAC address table. If the address is found, the frame goes out of one port. If it is not found, the frame is flooded.
- A broadcast destination is never looked up. The switch sends the frame out of every port except the one it arrived on.
- A multicast destination is treated like broadcast by default. A basic switch has no way to know which ports have listeners, so it floods. Switches that run IGMP snooping or MLD snooping can restrict multicast to interested ports, but that is outside this chapter.
Group addresses are never learned
A group address is only valid as a destination. No interface should use one as its source address. The switch therefore learns only from unicast source addresses. In the code, if not is_group(src) skips learning for a source with the group bit set. This keeps invalid entries out of the table.
Common errors
- Reading the wrong octet. Mixing up byte order, or testing the last octet instead of the first, misclassifies addresses. Test the first octet.
- Treating every non-broadcast group address as unicast. Multicast frames have no table entry, so they behave like broadcasts.
- Expecting a multicast frame to reach only the listeners on a basic switch. Every port receives it unless snooping is enabled.
Exercise
A frame arrives with destination 01:80:c2:00:00:0e. The switch's MAC table is empty. Is the address unicast, broadcast or multicast, and does the switch consult its table to choose an output port?
Show answer
The first octet is 01, whose last bit is 1, so the address is multicast (it is not all ones, so it is not broadcast). The switch does not use the table to choose a port. By default it floods the frame out of every port except the ingress port.
Exercise
Is 0a:11:22:33:44:55 a valid source address that the switch can learn? Explain.
Show answer
Yes. The first octet 0a is 00001010 in binary, so the group bit is 0 and the address is unicast. A switch can learn it as a source address.