# Controlling Traffic (\`tc\`)

While the `ip` tool gave us a way to fiddle with network links, it didn't really give us any good abilities to fiddle with the network.

`tc` fixes that by allowing you to tinker to your hearts content with the quality and characteristics of a link. You can do things like subtly corrupt, delay, reorder, or outright drop packets.

{% hint style="danger" %}
Be very careful using `tc` commands on a link you're SSH'd over. **You could lock yourself out!**
{% endhint %}

#### Causing a Delay on a Link:

```bash
tc qdisc add dev lo root netem delay 200ms
# qdisc: Queuing discipline
# dev: Device
# root: Modify egress
# netem: Network emulation
```

#### Show Rules on a Link:

```bash
tc qdisc show dev lo
```

Try it on a link with no settings, you can see the default Kernel settings!

#### Delete Rule on a Link

```bash
tc qdisc del dev lo root
```

#### Introduce Loss on a Link:

```
tc qdisc add dev lo root netem loss 10%
```

{% hint style="warning" %}
Try to avoid going over 15% packet loss, TCP starts to seriously degrade at that point.
{% endhint %}

#### Twins! Duplicate on a Link:

```bash
tc qdisc change dev lo root netem duplicate 1%
```

#### Packets can also be corrupted:

```bash
tc qdisc change dev lo root netem corrupt 5%
```

*Note that TCP has a checksum built in, and corruptions commonly cause a retransmit. Most user level applications do not see this.*

## Exercises

* See how much packet loss you can introduce before a connection between a database and a REPL (eg `psql`) starts failing.
* If you introduce, say 2%, corruption to a web server, does it still work? Are the pages reliably what they should be? Why? (Hint: Checksums)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pingcap.gitbook.io/chaos-workshop/a-menagerie-of-tools/controlling-traffic-tc.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
