Topologies and wireless networks
Physical and logical bus and star; Wi-Fi, SSIDs, WPA2 and CSMA/CA with RTS/CTS.
Do this lesson in the simulatorAt GCSE (F10.4) a topology was the shape of a network: star, bus, ring or mesh. At A level you need to separate two ideas. The physical topology is how the devices are actually cabled together. The logical topology is how data actually flows between them. The two need not match, and the most common example of a mismatch is the network you are probably using now: Wi-Fi.
Bus and star, physically
In a physical bus every device is connected to one shared cable, the backbone, with a terminator at each end to stop signals reflecting back. In a physical star every device has its own cable to a central device, a switch or a hub.
| Physical bus | Physical star | |
|---|---|---|
| Cabling | one backbone, short drops: cheap, easy to extend | a cable per device: more cable, more cost |
| A cable fails | the whole network stops | only that one device is cut off |
| The centre fails | there is no centre | every device is cut off |
| Busy network | all devices share one cable, so collisions increase and performance falls | a switch gives each device its own link, so performance holds up |
| Security | every device receives every signal | a switch sends frames only to the port they are for |
| Finding a fault | hard: the fault could be anywhere on the backbone | easier: test one cable at a time |
Physical star, logical bus
What happens in the centre of a star decides its logical topology.
A hub is a simple repeater: whatever arrives on one port, it sends out of every other port. So although the network is wired as a star, every device receives every frame and they all share one channel, taking turns exactly as they would on a bus cable. That is a physical star with a logical bus topology.
A switch reads the destination MAC address of each frame and sends it only out of the port where that device is. Data now flows along the arms of the star only, so it is a physical star and a logical star.
Wireless networks are the same. Devices all talk to one access point, so physically it looks like a star, but the radio is a single shared medium: every device in range hears every transmission, and only one can transmit at a time without interference. Logically, it is a bus.
BugBot's radio is a logical bus too. send() has no address: every robot on the mat receives the message. This mat has a Neighbour robot sending frames that are nothing to do with you. Listen, and you hear them anyway:
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
wait(2)
for sender, text in messages():
print("heard", sender, "say", text)
Wireless networking
A wireless network interface controller (WNIC) is the hardware in a device that sends and receives radio signals and turns them into data. A wireless access point (WAP) connects wireless devices to each other and to a wired network, usually through a switch or router.
Wi-Fi is the family of wireless local area network standards (IEEE 802.11) that WNICs and access points use. Each network has a service set identifier (SSID): the network's name, up to 32 characters, which the access point normally broadcasts so devices can find it. A device must know the SSID to join.
Anyone in range can receive a wireless signal, so wireless networks need protecting:
| Measure | What it does | Its limit |
|---|---|---|
| Strong encryption (WPA2 or WPA3) | encrypts every frame; a device needs the key to join or to read traffic | only as strong as the passphrase |
| Disable SSID broadcast | the network is not listed for casual users | the SSID still appears in frames other devices send, so a determined attacker finds it |
| MAC address allow list | only devices whose MAC address is on the list may connect | MAC addresses can be copied (spoofed) from captured frames |
CSMA/CA
On a shared medium, two devices transmitting at once make a collision and both frames are lost. Wired Ethernet on a bus detects collisions while sending. A wireless device cannot: its own signal is so much stronger than anyone else's at its antenna that it cannot hear a collision happen. So Wi-Fi tries to avoid collisions instead, using carrier sense multiple access with collision avoidance (CSMA/CA):
- Listen (carrier sense): is anyone transmitting?
- If the channel is busy, wait a random back-off time, then listen again. The randomness matters: two devices that both waited for the same transmission to end would otherwise both start at once.
- When the channel has been idle for a set time, transmit the frame.
- The receiver checks the frame and, if it is intact, sends an acknowledgement (ACK). No ACK means the frame was lost, probably in a collision, so the sender backs off and tries again.
RTS/CTS
There is a trap. Devices A and C are both in range of the access point, but on opposite sides and out of range of each other. A listens, hears nothing, and transmits. C listens, hears nothing, and transmits. Both frames collide at the access point. This is the hidden node problem.
Request to send / clear to send (RTS/CTS) fixes it. After sensing an idle channel, the sender transmits a short RTS frame. The access point replies with a CTS frame. Every device in range of the access point hears the CTS, including hidden ones, and stays quiet for the time it announces. The sender then transmits its data and waits for the ACK. RTS and CTS are tiny, so if they collide little time is wasted.
In AQA-style pseudo-code:
REPEAT
WHILE channel is busy
wait a random back-off time
ENDWHILE
send RTS
wait for CTS
send data frame
wait for ACK
UNTIL ACK received
Task: wait for a quiet channel
The Neighbour is sending frames for the first couple of seconds. The AccessPoint replies CTS bot when it hears RTS, and ACK bot when it hears a message starting DATA. Both replies come about 0.2 s later.
Carry out CSMA/CA with RTS/CTS:
- Call
messages()once to clear anything old. Then listen for a window of 0.4 s:wait(0.4), thenmessages(). - If anything arrived in the window, print
busy, backing off, wait a random time from 0.1 to 0.5 seconds (random.uniform(0.1, 0.5)), and listen for another window. Repeat until a window is silent. - Print
channel clearand sendRTS. - Wait for a message starting
CTS, checkingmessages()every 0.1 s for up to 2 seconds. When it comes, printgot CTSand sendDATA hello. - Wait the same way for a message starting
ACK, then printgot ACK.
The robot does not drive.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
import random
send("RTS")
wait(1)
print(messages())
Challenges
- Count how many times you backed off and print the total. Run it with different values in
random.uniform: what changes? - Real Wi-Fi doubles the maximum back-off each time a frame goes unacknowledged. Add that to your retry loop.
- Draw a physical star with a switch at the centre. Explain why its logical topology is a star, not a bus.