Test a network before you build it
A school wants to know if its network will cope when every class streams a video at once. Nobody buys the cables to find out. Engineers build the network inside a program, a simulator, and run it to see what the packets would do.
By the end of this lesson
Note
I can run a simulated network and read its delay and its packet loss.
Key words
- Simulator: a program that imitates a network.
- Node: one computer in the network.
- Delay: how long a bit takes to cross a link.
- Data rate: how many bits a link carries each second.
- Packet loss: packets sent that never arrive.
Starter: what you already know
Note
Answer in your head. 1. What is a packet? 2. What does a router do? 3. Is a faster link the same as a shorter link? You need the third answer in a moment.
Before you start
Note
Press Start the lab on the bar at the top of this lesson. This lab is a whole Ubuntu machine of your own, so it takes a little longer to come up than a container. Each Run button types its command into the machine's terminal, one after another in the same session. If one says the machine is still starting, wait a few seconds and press it again. To watch them, or to type your own, press Open terminal on the bar.
A network is a short program
Your files are in the folder ns3. The first command moves into it. first.cc makes two nodes, joins them with one link and sends one packet to an echo server, which sends it back. sim build compiles it against ns-3 and takes a few seconds. The program is then called first. Run it: the first line says when the client sent its packet, and the second says when the reply came back.
cd ns3Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
sim build first.ccShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
./firstShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Check
Tip
How long did the round trip take? Answer: a little over 7 milliseconds. The client sent at 2 seconds and the reply came at about 2.0074 seconds.
A trace shows every packet
ns-3 also wrote first-0-0.pcap, a record of every packet that crossed node 0's device. A pcap file is the real format tools such as tcpdump read. sim pcap lists it, one packet a line, with its time in seconds. There are two lines: the request at 2.000000 and the reply a few milliseconds later, each with 1024 bytes of data.
sim pcap first-0-0.pcapShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
A common mistake
Warning
Many people think a link's speed is how fast a packet travels. It is not. The delay is how long a bit takes to cross, and the data rate is how fast a node can put bits onto the link. A slow link makes a big packet take longer to send. A long link makes every packet take longer to arrive, big or small.
Delay and data rate are different
The two settings are on the command line. The first Run gives the link a long delay and keeps the rate. The second keeps the delay and slows the rate to 1 Mbps. Compare both with the round trip you saw before, a little over 7 ms. A 50 ms delay adds about 96 ms, because the packet crosses twice. Slowing the rate adds about 13 ms, because every bit takes longer to put onto the wire.
./first --delay=50msShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
./first --rate=1MbpsShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Check
Tip
Which setting does the size of the packet change? Answer: the data rate. A bigger packet has more bits to put on the wire, and the delay is the same for every packet.
A bottleneck loses packets
bottleneck.cc has senders that each have a fast link to a router, and one slower link from the router to the receiver. FlowMonitor counts what each flow sent and what arrived. With two senders of 4 Mbps into the 10 Mbps bottleneck, every packet arrives. The second Run sends five flows of 1 Mbps into a 4 Mbps link: about a fifth of each flow is lost, because the router's queue is full and it drops what it cannot hold.
sim build bottleneck.ccShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
./bottleneck --senders=2Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
./bottleneck --senders=5 --each=1Mbps --bottleneck=4MbpsShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Exit check
Tip
Answer without looking back. 1. What does a simulator do? 2. What is a pcap file? 3. Which setting does a bigger packet slow down, the delay or the data rate? 4. When is a packet lost at a bottleneck? Answers: imitates a network in a program; a record of the packets on a device; the data rate; when more is sent than the link can carry and the queue is full. Now open README.md in your home folder with cat ~/README.md: you write two scenarios.
For teachers
Tip
This lesson is a small example of a lesson worked in a lab: the steps and the Run buttons are the lesson, and the lab is each student's own copy. This lesson is worked in a VM lab: each student has an Ubuntu machine of their own with ns-3 installed, and a Run types into its terminal and shows what it printed. Key learning points: 1. A simulator imitates a network in a program. 2. A trace records every packet. 3. Delay and data rate are different, and a bigger packet is slowed by the rate. 4. Packets are lost when more is sent than a link carries. Common mistake: thinking speed and delay are the same. Equipment: the lab and a browser. Tip: before the 1 Mbps Run, ask the class which will change more, the delay or the rate. The lab itself has a check that marks two C++ programs with hidden values. Copy it into your own module and change it, or build one from scratch with the Lab menu in the lesson builder.