Skip to content

Commit

Permalink
feat(rust): add tcp-test tool to measure portal properties
Browse files Browse the repository at this point in the history
  • Loading branch information
davide-baldo committed Dec 17, 2024
1 parent 5277ba0 commit 058b226
Show file tree
Hide file tree
Showing 10 changed files with 760 additions and 5 deletions.
58 changes: 54 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"tools/docs/example_blocks",
"tools/docs/example_test_helper",
"tools/stress-test",
"tools/tcp-test",
]

# Coverage profile for generating code coverage with grcov.
Expand Down
3 changes: 3 additions & 0 deletions NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ This file contains attributions for any 3rd-party open source code used in this
| parking_lot_core | MIT, Apache-2.0 | https://crates.io/crates/parking_lot_core |
| paste | MIT, Apache-2.0 | https://crates.io/crates/paste |
| pathdiff | MIT, Apache-2.0 | https://crates.io/crates/pathdiff |
| pem | MIT | https://crates.io/crates/pem |
| pem-rfc7468 | Apache-2.0, MIT | https://crates.io/crates/pem-rfc7468 |
| percent-encoding | MIT, Apache-2.0 | https://crates.io/crates/percent-encoding |
| petname | Apache-2.0 | https://crates.io/crates/petname |
Expand Down Expand Up @@ -420,6 +421,7 @@ This file contains attributions for any 3rd-party open source code used in this
| rand_pcg | MIT, Apache-2.0 | https://crates.io/crates/rand_pcg |
| rayon | MIT, Apache-2.0 | https://crates.io/crates/rayon |
| rayon-core | MIT, Apache-2.0 | https://crates.io/crates/rayon-core |
| rcgen | MIT, Apache-2.0 | https://crates.io/crates/rcgen |
| redox_syscall | MIT | https://crates.io/crates/redox_syscall |
| reedline | MIT | https://crates.io/crates/reedline |
| regex | MIT, Apache-2.0 | https://crates.io/crates/regex |
Expand Down Expand Up @@ -649,6 +651,7 @@ This file contains attributions for any 3rd-party open source code used in this
| xml-rs | MIT | https://crates.io/crates/xml-rs |
| xmlparser | MIT, Apache-2.0 | https://crates.io/crates/xmlparser |
| yaml-rust | MIT, Apache-2.0 | https://crates.io/crates/yaml-rust |
| yasna | MIT, Apache-2.0 | https://crates.io/crates/yasna |
| yoke | Unicode-3.0 | https://crates.io/crates/yoke |
| yoke-derive | Unicode-3.0 | https://crates.io/crates/yoke-derive |
| zerocopy | BSD-2-Clause, Apache-2.0, MIT | https://crates.io/crates/zerocopy |
Expand Down
2 changes: 1 addition & 1 deletion tools/stress-test/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function scp {
TARGET_ARCHITECTURE=$(ssh uname -m)

# always use cross-compilation to avoid reliance on new and unsupported glibc versions
cross build --bin=stress-test --bin=ockam -F aws-lc --release --target "${TARGET_ARCHITECTURE}-unknown-linux-gnu"
DOCKER_DEFAULT_PLATFORM=linux/amd64 cross build --bin=stress-test --bin=ockam -F aws-lc --release --target "${TARGET_ARCHITECTURE}-unknown-linux-gnu"
echo "uploading..."

scp \
Expand Down
14 changes: 14 additions & 0 deletions tools/tcp-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "tcp-test"
version = "0.1.0"
edition = "2021"
license = "Apache-2.0"
publish = false
readme = "README.md"

[dependencies]
clap = { version = "4", features = ["derive", "cargo", "env"] }
rcgen = { version = "0.13", features = ["pem", "aws_lc_rs"], default-features = false }
rustls = { version = "0.23" }
tokio = { version = "1", features = ["full"] }
tokio-rustls = { version = "0.26", features = ["aws-lc-rs"] }
89 changes: 89 additions & 0 deletions tools/tcp-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
This tool is useful to test the portal capabilities and operates as a **generic** TCP client and server.
It also implements (unsafe) TLS, which is useful for performance comparison.

# Deployment

Can be easily deployed via ssh using the `deploy` script:
```bash
$ ./deploy user@host
```

# Actions

# latency
Measures the latency of a TCP packets to a given host and port.
It must be used with an echo server.

```bash
$ tcp-test echo 1234
Listening on 0.0.0.0:1234

$ tcp-test latency 127.0.0.1:1234
Connection + First RTT: 0ms 440us, Second RTT: 0ms 143us
Connection + First RTT: 0ms 192us, Second RTT: 0ms 160us
Connection + First RTT: 0ms 276us, Second RTT: 0ms 162us
Connection + First RTT: 0ms 326us, Second RTT: 0ms 155us
Connection + First RTT: 0ms 227us, Second RTT: 0ms 172us
Connection + First RTT: 0ms 250us, Second RTT: 0ms 111us
Connection + First RTT: 0ms 461us, Second RTT: 0ms 122us
Connection + First RTT: 0ms 326us, Second RTT: 0ms 116us
Connection + First RTT: 0ms 320us, Second RTT: 0ms 104us
Connection + First RTT: 0ms 270us, Second RTT: 0ms 101us
Average - Connection + First RTT: 0ms 309us, Second RTT: 0ms 135us
```

# flood
Floods a given host and port with connections until it fails or reaches the provided maximum.
It's meant to measure the maximum number of connections a portal can handle.
It must be used with an echo server.

Example:
```bash
$ tcp-test echo 1234
Listening on 0.0.0.0:1234

$ tcp-test flood 127.0.0.1:1234
Failed to connect: Os { code: 49, kind: AddrNotAvailable, message: "Can't assign requested address" }
Flooded 16344 connections
Pinging each...
All connections succeeded
```
# throughput
Measures the throughput of a TCP connection to a given host and port.
It can be used to measure the throughput of a portal, especially to compare a portal against TLS.
Can be used in conjunction with a null server for results similar to `iperf3`, but echo can also be
used for a full bandwidth test.
```bash
$ tcp-test null 1234
Listening on 0.0.0.0:1234

$ tcp-test throughput 127.0.0.1:1234
Outgoing Throughput: 70.44 Gbps
Outgoing Throughput: 75.12 Gbps
Outgoing Throughput: 75.44 Gbps
Outgoing Throughput: 78.43 Gbps
Outgoing Throughput: 71.89 Gbps
Outgoing Throughput: 69.80 Gbps
Outgoing Throughput: 75.13 Gbps
^C
```
## echo
It starts a TCP server that listens to on a given port and **echoes back** any data it receives.
It's meant to be used in conjunction with the other actions.
```bash
$ tcp-test echo 1234
Listening on 0.0.0.0:1234
```
# null
It starts a TCP server that listens to on a given port and **discards** any data it receives.
It's meant to be used in conjunction with the other actions.
```bash
$ tcp-test null 1234
Listening on 0.0.0.0:1234
```
35 changes: 35 additions & 0 deletions tools/tcp-test/deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# This scripts deploys a tcp test client and an ockam client to a remote machine accessible via ssh.

set -e

cd "$(dirname "$0")"/../../

if [ "$#" -lt 1 ]; then
echo "usage: $0 <[username@]host>"
exit 1
fi

export SSH_ENDPOINT="$1"

function ssh {
/usr/bin/env ssh -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=QUIET -o ConnectTimeout=5 "${SSH_ENDPOINT}" "$@"
}

function scp {
/usr/bin/env scp -q -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=QUIET -o ConnectTimeout=5 "$@"
}

TARGET_ARCHITECTURE=$(ssh uname -m)

# always use cross-compilation to avoid reliance on new and unsupported glibc versions
DOCKER_DEFAULT_PLATFORM=linux/amd64 cross build --bin=tcp-test --bin=ockam -F aws-lc --release --target "${TARGET_ARCHITECTURE}-unknown-linux-gnu"
echo "uploading..."

scp \
"target/${TARGET_ARCHITECTURE}-unknown-linux-gnu/release/ockam" \
"target/${TARGET_ARCHITECTURE}-unknown-linux-gnu/release/tcp-test" \
"${SSH_ENDPOINT}:"

ssh sudo mv ockam tcp-test /usr/local/bin/
Loading

0 comments on commit 058b226

Please sign in to comment.