Switches
A switch joins the devices in one place, such as the computers on one floor of an office. Each device has its own cable to the switch. The switch passes each message only to the device it is for. Nobody tells the switch where the devices are. It learns that from the messages that pass through it.
Ports and frames
A switch has a row of sockets called A socket on a switch or router for one cable. Each port has a name or number, so you can tell which cable is which., numbered 1, 2, 3, and so on. Each device's cable plugs into one port.
One word, two meanings
"Port" also means something different: a number that picks one program on a computer. You meet that kind in Ports and protocols. In this lesson, a port is always a socket.
Inside one local network, messages travel in A message on the local network: a packet wrapped with the hardware addresses of the device it is for and the device that sent it.. A frame is a packet in an outer envelope. The envelope has two of the hardware addresses from Addresses:
- To: the hardware address of the device the frame is for.
- From: the hardware address of the device that sent it.
A switch reads only these two addresses. It does not look at the IP addresses inside, and it does not change the frame. Wi-Fi sends the same frames over radio.
How a switch learns
When a switch is turned on, it knows nothing about the devices plugged into it. Its The list a switch keeps of which hardware address is behind which of its ports. Also called the MAC address table., the list of which device is behind which port, is empty.
The numbered squares are the switch's ports. Send a frame, and watch which ports it goes out of.
The switch’s address table
| Hardware address | Port | Who that is |
|---|---|---|
| Empty | ||
The switch knows only the first two columns. The third is there for you.
Things to try
- See the switch flood a frame it cannot place yet. Not yet.
- Get a frame sent out of one port only. Not yet.
- Teach the switch where all five devices are. Not yet.
- Send a broadcast, a frame for everyone. Not yet.
Each time a frame arrives, the switch does four things:
- It reads the frame's From address. It writes in its table that this address is behind the port the frame came in on.
- It looks for the frame's To address in the same table.
- If it finds the address, it sends the frame out of that one port only.
- If it does not, it sends a copy out of every port except the one the frame came in on. This is called Sending a copy of a frame out of every port except the one it came in on. A switch floods a frame when it does not know yet where the receiver is.. A device that gets a copy that is not addressed to it ignores it.
The switch learns only from the sender, never from the receiver. A frame to the printer teaches the switch nothing about the printer. Only a frame from the printer does.
Flooding lasts only a moment. Devices that talk to each other answer each other, and every answer teaches the switch one more row. On a busy network, the table fills within seconds. After that, almost every frame goes out of exactly one port.
Forgetting, and moving devices
A switch does not keep a row forever. If no frame comes from an address for a while, often five minutes, the switch removes that row. When the device talks again, the switch learns it again.
So a device can move. Plug the laptop into another port, or carry it to a desk on another switch. The first frame it sends from the new place updates the table, and frames for the laptop then follow it there.
Broadcasts: a frame for everyone
Sometimes a device needs to ask every device on the network at once, because it does not know which one to ask. It sends a A frame for every device on the local network, sent to the hardware address ff:ff:ff:ff:ff:ff.: a frame whose To address is ff:ff:ff:ff:ff:ff. This is the hardware address where every bit is 1, and it means "everyone".
A switch sends a broadcast out of every port except the one it came in on, as it does when it floods. The difference is at the other end. Every device keeps a broadcast and reads it, because it is for all of them.
A common broadcast asks "which of you has the IP address 192.168.1.30?". The device with that address answers with its hardware address. This question is called Address Resolution Protocol: how a device finds the hardware address that belongs to an IP address on its own network. It asks every device at once, with a broadcast., and you try it in the next lesson.
Frame 1 of 5
A frame arrives on port 1
- To
- 02:7c:e1:46:a8:3c
- From
- 3a:91:5c:0e:72:1a
The address table before it
| Hardware address | Port |
|---|---|
| Empty | |
Which ports does it go out of?
Read the frame's To address, then look for it in the table. You can see which device is behind each port, but the switch knows only its table.
One local network
Everything a broadcast can reach is one local network, also called a Local area network: the devices in one place, such as a home or an office, joined by cables and Wi-Fi. They reach each other directly, without a router., short for local area network. The devices in your home are one LAN. So are the computers on one floor of an office.
A LAN can be bigger than one switch. Plug one switch into a port of another, and frames pass between them. Each switch writes in its table that every device on the other switch is behind the port that joins them. Both switches and every device on them are one LAN, and a broadcast from any device reaches all of it.
A switch cannot send a frame to a different network, such as your internet provider's. A hardware address only means something inside its own local network, and a switch reads only hardware addresses. A router joins one network to another, as the next lesson shows.