Network hardware and connections
NICs, switches, routers and access points; copper, fibre and wireless; Wi-Fi, Ethernet and Bluetooth.
Do this lesson in the simulatorA network needs hardware to connect each device, and a way for the bits to travel between them: cables or radio waves. This lesson names the boxes you would find in a school's network cupboard, compares wired with wireless, and builds a model of the switch, the device at the centre of most LANs.
The hardware
| Hardware | What it does |
|---|---|
| Network interface card (NIC) | connects a device to a network. Every NIC has a unique MAC address set when it is made. Today it is usually a chip built into the device |
| Switch | connects the devices in a LAN. It reads the MAC address on each frame of data and sends it only to the device it is for |
| Router | connects different networks together, such as a school's LAN to the internet. It reads the IP address on each packet and sends it on towards its destination |
| Wireless access point (WAP) | lets devices connect to a wired network by radio: Wi-Fi |
| Transmission media | what the data travels through: copper cable, fibre optic cable, or radio waves |
A home "router" is several of these in one box: a router, a switch, a wireless access point and a modem.
Transmission media
- Copper cable (Ethernet cable) carries data as electrical signals. It is cheap, but the signal weakens over about 100 m.
- Fibre optic cable carries data as pulses of light. It is faster and works over many kilometres without interference, but costs more.
- Radio waves carry wireless data. No cables are needed, but walls, distance and other devices weaken the signal.
Wired and wireless
| Wired (Ethernet) | Wireless (Wi-Fi) | |
|---|---|---|
| Speed | usually faster | usually slower, and shared |
| Reliability | steady; little interference | affected by walls, distance and other networks |
| Security | someone needs a physical connection | signals can be picked up outside the building, so they must be encrypted |
| Movement | devices stay where the cable is | devices can move around |
| Cost to set up | cables must be run to every device | fewer cables |
Wi-Fi is the standard for wireless LANs, using radio at 2.4 GHz or 5 GHz, split into channels so that nearby networks do not interfere. It is encrypted with a standard such as WPA2 or WPA3, so a device needs the password to join and cannot read other people's data. Bluetooth is a short-range wireless standard for connecting a few devices close together, such as a phone and earbuds: a PAN. Ethernet is the standard for wired LANs.
BugBot's Vision board has a separate chip just for Wi-Fi, which links the robot to its USB dongle, while a USB cable connects it directly to a computer.
How a switch learns
A switch starts knowing nothing. Each time a frame arrives, it notes which port that sender's MAC address is on. When a frame is for an address it already knows, it sends it to that port only. When it does not know, it sends it out of every port:
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
table = {} # MAC address -> port
frames = [(1, "AA-01", "BB-02"), (2, "BB-02", "AA-01")] # (port it came in on, from, to)
for port, source, destination in frames:
table[source] = port # learn where the sender is
if destination in table:
print(source, "->", destination, ": port", table[destination])
else:
print(source, "->", destination, ": every port")
print(table)
Task: a learning switch
Complete the switch. For each frame in frames, learn which port its source is on. Then print frame to <destination>: port <n> if the destination is known, or frame to <destination>: every port if not. At the end, print learned <n> addresses.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# (port it came in on, source MAC, destination MAC)
frames = [
(1, "AA-01", "BB-02"),
(2, "BB-02", "AA-01"),
(3, "CC-03", "AA-01"),
(1, "AA-01", "CC-03"),
(4, "DD-04", "BB-02"),
]
table = {}
Challenges
- A hub is an older device that sends every frame out of every port. Count how many frames a hub would have sent to the wrong device.
- Add a frame from a device that has moved to a different port. What should the switch do?
- A school is building a new sports hall 400 m away. Recommend copper, fibre or wireless for the link, with two reasons.