UDP datagrams
On this page
Some exchanges need one question and one answer. Opening and closing a connection could add more messages than the useful exchange itself. You will watch one question and answer, then see what UDP does for the program and what the program must do itself.
Before you start
Section titled “Before you start”Finish Opening and closing TCP connections. Leave machine shells and run netlab reset from the VM if needed. This experiment temporarily enables the lab’s lookup service. You need not understand the lookup’s contents yet. How DNS Finds Services teaches what the question and answer mean.
At the VM prompt run netlab mode dns on, answering sudo’s password question. The mode command rebuilds the running lab itself, so leave all machine shells before using it. Check netlab status, then open two terminals on laptop. The replay labels the status check with a comment after #; Bash ignores that comment.
learner@rootvolt:~$ netlab mode dns on[sudo] password for learner: Mode dns is on: dns and ns run; lab machines use 10.77.20.53.learner@rootvolt:~$ netlab status # dns is onLab is up. Modes on: dns. Fault: none.
MACHINE NETWORK ADDRESS DEFAULT ROUTE COMPARED WITH THE START
laptop home 10.77.10.10/24 10.77.10.1 same
phone home 10.77.10.11/24 10.77.10.1 same
router home, site 10.77.10.1/24 10.77.20.1/24 - same
web site 10.77.20.80/24 10.77.20.1 same
dns site 10.77.20.53/24 10.77.20.1 same
ns site 10.77.20.54/24 10.77.20.1 same
Switch sw-home (home): laptop, phone, router
Switch sw-site (site): dns, ns, router, web
Services: web http 80, web https 443, web http 8080, web ssh 22, dns dns 53, ns dns 53learner@rootvolt:~$ Steps (9)
- Type
netlab mode dns on - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- Output:
Mode dns is on: dns and ns run; lab machines use 10.77.20.53. - Type
netlab status # dns is on - Press Enter
- Output:
Lab is up. Modes on: dns. Fault: none. MACHINE NETWORK ADDRESS DEFAULT ROUTE COMPARED WITH THE START laptop home 10.77.10.10/24 10.77.10.1 same phone home 10.77.10.11/24 10.77.10.1 same router home, site 10.77.10.1/24 10.77.20.1/24 - same web site 10.77.20.80/24 10.77.20.1 same dns site 10.77.20.53/24 10.77.20.1 same ns site 10.77.20.54/24 10.77.20.1 same Switch sw-home (home): laptop, phone, router Switch sw-site (site): dns, ns, router, web Services: web http 80, web https 443, web http 8080, web ssh 22, dns dns 53, ns dns 53
Count the messages around the answer
Section titled “Count the messages around the answer”In terminal 1 run sudo tcpdump -n -i eth0 udp port 53. The filter selects UDP traffic involving port 53. In terminal 2 run dig +short web.lab.test. Here dig sends a lookup, and +short asks for brief printed output. Return to terminal 1 and stop with Ctrl+C.
Predict: how many captured rows will this exchange have compared with the page request’s twelve TCP rows?
learner@laptop:~$ sudo tcpdump -n -i eth0 udp port 53[sudo] password for learner: tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes08:26:51.000870 IP 10.77.10.10.42569 > 10.77.20.53.53: 50716+ [1au] A? web.lab.test. (53)
08:26:51.001345 IP 10.77.20.53.53 > 10.77.10.10.42569: 50716* 1/1/1 A 10.77.20.80 (90)^C2 packets captured
2 packets received by filter
0 packets dropped by kernellearner@laptop:~$ Steps (10)
- Type
sudo tcpdump -n -i eth0 udp port 53 - Press Enter
- Output:
[sudo] password for learner: - Type the password (the terminal shows nothing)
- Press Enter
- Output:
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes - The second terminal finished. Return here and press Ctrl+C to stop listening.
- Output:
08:26:51.000870 IP 10.77.10.10.42569 > 10.77.20.53.53: 50716+ [1au] A? web.lab.test. (53) 08:26:51.001345 IP 10.77.20.53.53 > 10.77.10.10.42569: 50716* 1/1/1 A 10.77.20.80 (90) - Press Ctrl + C
- Output:
2 packets captured 2 packets received by filter 0 packets dropped by kernel
learner@laptop:~$ dig +short web.lab.test10.77.20.80learner@laptop:~$ Steps (3)
- Type
dig +short web.lab.test - Press Enter
- Output:
10.77.20.80
Check your answer
There are two rows: one to 10.77.20.53 on port 53 and one back. The previous lesson’s recorded TCP request has twelve rows. These counts describe these runs, not a fixed count for all lookups or page requests.
UDP, the User Datagram Protocol, sends separate messages without TCP’s connection opening. A datagram is one such message, kept separate from other messages. UDP still has source and destination ports. The answer swaps the address-and-port pairs, so it goes back to the program that asked.
Read both captured rows, even though dig prints only one short result. Dig prints the answer for you. Tcpdump shows the messages sent between laptop and the lookup service.
Give the program the remaining work
Section titled “Give the program the remaining work”UDP adds no transport sequence numbering or acknowledgments. The receiving program gets separate datagrams. UDP does not put them back in the order they were sent.
If a datagram is lost, UDP does not retransmit it. The program must decide whether an answer is missing and whether another attempt is useful. An application reply is still possible, as the captured answer shows. The application chooses to send that reply. UDP itself sends no acknowledgment.
No datagram is lost in this recording, so it does not show what happens after a loss. It shows an exchange without a transport handshake. The table lists what TCP and UDP do. This capture does not test every item in the table.
| Attribute | TCP | UDP |
|---|---|---|
| Connection | Agrees to talk first | No transport handshake |
| Ordering | Delivers bytes in order | Does not put datagrams in order |
| Loss handling | Resends missing bytes | Program must handle loss |
| Typical uses | File transfer, many web exchanges | Lookups, calls, game updates |
Choose based on the application’s needs. A file needs every byte in order. An old game update may no longer help after a later update arrives. The program must still handle missing, repeated or late messages when they matter.
Mistakes to recognize
Section titled “Mistakes to recognize”“UDP is unreliable, so it is bad.” UDP leaves more decisions to the program. That can suit a program built to handle them. The captured lookup succeeds without TCP’s opening.
“UDP is always faster.” Two rows instead of twelve do not prove UDP is always faster. The network, message size and program all affect how long an exchange takes.
Good to know
Section titled “Good to know”Some application protocols can use either transport. This lookup uses UDP. That does not mean every lookup does. Likewise, a port number alone does not identify an application. The next lesson tests that assumption directly.
Your client port and the lookup’s identifier vary; your number will differ. Compare the reversed pairs and row kinds instead of copying the sample’s temporary values.
Try it yourself
Section titled “Try it yourself”Before running again, predict which pairs reverse in the answer and whether a FIN row will appear. Run the two-terminal lookup experiment again. Compare your own rows with the prediction, and say whether two successful rows promise that the next datagram will arrive.
Solution
The address-and-port pairs reverse. There is no TCP FIN because this is a UDP exchange. A successful answer does not promise every later datagram will arrive. Use the two replays as a check on direction, not a promise about temporary client ports.
Stop listeners, leave machine shells, and run netlab mode dns off from the VM. Check netlab status; this cleanup replay shows Modes on: none. Later experiments tell you when to enable the lookup service again.
learner@rootvolt:~$ netlab mode dns offMode dns is off.learner@rootvolt:~$ netlab status # dns is offLab is up. Modes on: none. Fault: none.
MACHINE NETWORK ADDRESS DEFAULT ROUTE COMPARED WITH THE START
laptop home 10.77.10.10/24 10.77.10.1 same
phone home 10.77.10.11/24 10.77.10.1 same
router home, site 10.77.10.1/24 10.77.20.1/24 - same
web site 10.77.20.80/24 10.77.20.1 same
Switch sw-home (home): laptop, phone, router
Switch sw-site (site): router, web
Services: web http 80, web https 443, web http 8080, web ssh 22learner@rootvolt:~$ Steps (6)
- Type
netlab mode dns off - Press Enter
- Output:
Mode dns is off. - Type
netlab status # dns is off - Press Enter
- Output:
Lab is up. Modes on: none. Fault: none. MACHINE NETWORK ADDRESS DEFAULT ROUTE COMPARED WITH THE START laptop home 10.77.10.10/24 10.77.10.1 same phone home 10.77.10.11/24 10.77.10.1 same router home, site 10.77.10.1/24 10.77.20.1/24 - same web site 10.77.20.80/24 10.77.20.1 same Switch sw-home (home): laptop, phone, router Switch sw-site (site): router, web Services: web http 80, web https 443, web http 8080, web ssh 22
- Recognize a datagram exchange without a transport opening.
- Separate application answers from transport acknowledgments.
- Choose delivery services based on the program’s needs.
Next, Choosing and recognizing transports compares service evidence with port-number guesses.