Data communications
For any two devices to exchange information you need much more than a cable: you need rules. Protocols organize those rules in layers, and that organization is what allowed networks of completely different technologies to connect with one another.
01The layer model
| OSI layer | What it deals with | Example |
|---|---|---|
| 7 Application | The service the user sees. | HTTP, SMTP, Modbus, MQTT |
| 6 Presentation | Format, encoding and encryption. | TLS, JSON, compression |
| 5 Session | Establishing and maintaining the dialogue. | session opening and closing |
| 4 Transport | End-to-end delivery, ordering and flow control. | TCP, UDP |
| 3 Network | Logical addressing and routing. | IP |
| 2 Data link | Frames, physical addresses and error detection. | Ethernet, HDLC, CAN |
| 1 Physical | Levels, connectors, line coding, medium. | RS-485, fiber, radio |
So that you can change one without touching the others. The same web page travels the same way over fiber, WiFi or satellite: only the physical layer changes. And the same Ethernet cable carries HTTP, e-mail or Modbus without knowing what it is carrying inside.
In practice the four-layer TCP/IP model is used, which groups the top three into one. The seven-layer model is useful for reasoning and for locating where a problem is, which is exactly what you need when troubleshooting.
02Circuits or packets
A complete path is reserved for the whole duration of the communication, as in classic telephony. The delay is fixed and the bandwidth is guaranteed.
In exchange, the resource stays occupied even if nobody is speaking, and setting up the connection takes time. For bursty data it is an enormous waste.
The information is split into packets that travel independently and share the links with everyone else's. It is what the internet does.
It makes far better use of resources and tolerates the loss of a link, because the packets take another path. In exchange, the delay is variable and there is no automatic bandwidth guarantee.
Because voice needs a small, constant delay, and packets arrive with variable delays. The solution is a jitter buffer in the receiver, which accumulates a few milliseconds and delivers at an even pace. That buffer adds delay in exchange for regularity: if it is short, you hear dropouts; if it is long, the conversation becomes awkward.
03Detecting and correcting errors
| Method | What it detects | Cost |
|---|---|---|
| Parity | An odd number of erroneous bits. If two flip, it doesn't notice. | 1 bit |
| Checksum | Simple errors. Byte permutations slip past it. | 1 or 2 bytes |
| CRC | Practically all errors, including bursts shorter than its length. It is what Ethernet, CAN and Modbus use. | 2 or 4 bytes |
| Hamming | Detects two errors and corrects one. Used in memories. | several bits |
| Convolutional codes and Reed-Solomon | Correct long bursts without retransmitting. Digital radio, satellite, disks. | 25 to 50% of the throughput |
- Detect and retransmit: the receiver discards what is damaged and asks again. It is efficient when errors are rare and the delay is short. It is what TCP does.
- Correct at the receiver: enough redundancy is sent to repair without asking. It is what is appropriate when retransmitting is extremely expensive —a satellite, with half a second round trip— or simply impossible, as in a broadcast transmission.
A link with a BER of 10⁻⁵ carries frames of 1500 bytes, that is, 12,000 bits.
- Probability that a frame arrives intact: (1 − 10⁻⁵)12,000 ≈ 88.7%.
- So one frame in nine is discarded and has to be requested again.
- With 500-byte frames, the probability of arrival rises to 96%: fewer retransmissions, although more headers.
That is the reason noisy links use short frames, and clean ones, long frames. It is not an arbitrary choice: it comes from the error rate.
04Addressing and access networks
| Element | Function |
|---|---|
| Physical address | Identifies the network card within the local network. It comes from the factory and is not routed. |
| IP address | Identifies the device on the logical network. It is what lets you get out of the local network. |
| Subnet mask | Separates the network part from the host part: it defines who is a “neighbor” and who is outside. |
| Gateway | The device to which packets destined for other networks are handed. |
| Port | Identifies the service within the device: 80 for web, 502 for Modbus TCP. |
| ISDN | The integrated services digital network: two 64 kbit/s channels plus one 16 kbit/s channel for signaling. It was the first digital subscriber access, now superseded by broadband networks. |
A PLC with address 192.168.1.20 and mask 255.255.255.0 wants to talk to a server.
- If the destination is 192.168.1.55, the mask indicates it is on the same network: it hands the frame over directly.
- If the destination is 10.0.0.8, it is outside: it hands the frame to the gateway, which takes care of routing it.
- If the gateway is misconfigured, local communication works perfectly and remote communication never works. It is the symptom that identifies that configuration error.
05In the lab
With a protocol analyzer, capture real traffic and open a packet: identify the header of each layer and locate the application data inside it all. Measure how many bytes are header and how many are useful information.
With a short polynomial, calculate the CRC of a message of a few bytes and verify it. Then change one bit and check that the remainder no longer matches. Implement it on the microcontroller and compare with the manufacturer's library.
On your own serial link, add controlled noise and measure the rate of discarded frames with different frame sizes. Plot it and compare with the theoretical calculation from the measured BER.
Deliberately configure a wrong mask, a wrong gateway and a duplicate address, and learn to recognize the symptom of each case with the basic troubleshooting tools. Build your own symptom-cause table.
06Common mistakes
| Symptom | Usual cause |
|---|---|
| The local network works but internet access doesn't | Gateway misconfigured or missing. |
| Two devices can't see each other even though they are on the same switch | Different masks: each one thinks the other is on another network. |
| Intermittent, erratic communication | Duplicate IP address. |
| Relying only on parity | It does not detect an even number of erroneous bits, which is typical in noise bursts. |
| Long frames on a noisy link | Almost all are discarded and throughput collapses because of retransmissions. |
| Voice over IP with a very short buffer | You hear dropouts with every variation in delay. |
| Expecting retransmission on a satellite link | Half a second round trip: forward correction is the right choice. |
| Troubleshooting without thinking in layers | You look in the application for a problem that was in the cable, and vice versa. |
07Self-assessment
What is the point of organizing protocols in layers?
To be able to change one layer without touching the others: the same application travels over fiber, WiFi or satellite by changing only the physical layer.
What is encapsulation?
Each layer adds its own header on the way down and removes it on the way up, treating what it receives from above as data it does not need to interpret.
At which layer does IP work and at which TCP?
IP at the network layer —addressing and routing— and TCP at the transport layer —end-to-end delivery, ordering and flow control—.
Advantage and disadvantage of packet switching.
It makes far better use of resources and tolerates the loss of a link; in exchange the delay is variable and there is no automatic bandwidth guarantee.
Why does voice over IP need a jitter buffer?
Because packets arrive with variable delays and voice needs a constant pace. The buffer accumulates a few milliseconds and delivers evenly.
What limitation does the parity bit have?
It only detects an odd number of erroneous bits. If two flip, the parity matches again and the error goes unnoticed.
Why is CRC used in Ethernet, CAN and Modbus?
Because it detects practically all errors, including bursts shorter than its length, at a cost of only 2 or 4 bytes per frame.
When is forward error correction appropriate instead of retransmission?
When retransmitting is very expensive —a satellite link with half a second of delay— or impossible, as in a broadcast transmission.
Why do noisy links use short frames?
Because the probability that a frame arrives intact falls with its length: with long frames almost all are discarded and throughput collapses.
The local network works but there is no internet access. What do you check?
The gateway: if it is missing or misconfigured, packets to other networks don't get out, while local communication keeps working.