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 16, 2024
1 parent 5277ba0 commit fbe0134
Show file tree
Hide file tree
Showing 9 changed files with 729 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
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
11 changes: 11 additions & 0 deletions tools/tcp-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "tcp-test"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4", features = ["derive", "cargo"] }
tokio = { version = "1", features = ["full"] }
tokio-rustls = { version = "0.26", features = ["aws-lc-rs"] }
rcgen = { version = "0.13", features = ["pem", "aws_lc_rs"], default-features = false }
rustls = { version = "0.23" }
85 changes: 85 additions & 0 deletions tools/tcp-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
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
Throughput: 47.56066Gbits/s
Throughput: 48.83963Gbits/s
Throughput: 48.760296Gbits/s
^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 echo 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 fbe0134

Please sign in to comment.