Skip to content

Commit

Permalink
test: add tun based simulation test (IPv4 only) (#908)
Browse files Browse the repository at this point in the history
  • Loading branch information
fujiapple852 committed Jan 11, 2024
1 parent 9a7ccb8 commit a21e59c
Show file tree
Hide file tree
Showing 18 changed files with 841 additions and 5 deletions.
48 changes: 47 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,60 @@ jobs:
os: windows-latest
target: x86_64-pc-windows-msvc
rust: stable
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- run: cargo test --target ${{ matrix.target }}

sim-test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
build:
- linux-stable
- macos-stable
- windows-stable
include:
- build: linux-stable
os: ubuntu-20.04
target: x86_64-unknown-linux-gnu
rust: stable
- build: macos-stable
os: macos-latest
target: x86_64-apple-darwin
rust: stable
- build: windows-stable
os: windows-latest
target: x86_64-pc-windows-msvc
rust: stable
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
with:
toolchain: ${{ matrix.rust }}
target: ${{ matrix.target }}
- run: cargo test --workspace --all-features --target ${{ matrix.target }}
- name: Copy wintun.dll to current dir
if: startsWith(matrix.build, 'windows')
shell: bash
run: |
cp "tests/resources/wintun.dll" "."
- name: Allow ICMPv4 and ICMPv6 in Windows defender firewall
if: startsWith(matrix.build, 'windows')
shell: pwsh
run: |
New-NetFirewallRule -DisplayName "ICMPv4 Trippy Allow" -Name ICMPv4_TRIPPY_ALLOW -Protocol ICMPv4 -Action Allow
New-NetFirewallRule -DisplayName "ICMPv6 Trippy Allow" -Name ICMPv6_TRIPPY_ALLOW -Protocol ICMPv6 -Action Allow
- name: Run simulation test on ${{ matrix.build }}
if: ${{ ! startsWith(matrix.build, 'windows') }}
run: sudo -E env "PATH=$PATH" cargo test --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture
- name: Run simulation test on ${{ matrix.build }}
if: startsWith(matrix.build, 'windows')
run: cargo test --target --target ${{ matrix.target }} --features sim-tests --test sim -- --exact --nocapture

fmt:
runs-on: ubuntu-22.04
steps:
Expand Down
4 changes: 4 additions & 0 deletions Cargo.lock

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

9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,15 @@ ipnetwork = "0.20.0"
pretty_assertions = "1.4.0"
rand = "0.8.5"
test-case = "3.3.1"
serde_yaml = "0.9.30"
# see https://github.com/meh/rust-tun/pull/74
tun = { git = "https://github.com/ssrlive/rust-tun", features = [ "async" ] }
serde_yaml = "0.9.30"
tokio = { version = "1.35.1", features = [ "full" ] }
tokio-util = { version = "0.7.10" }

[features]
# Enable simulation integration tests
sim-tests = []

# cargo-generate-rpm dependencies
[package.metadata.generate-rpm]
Expand Down
Empty file removed tests/integration_tests.rs
Empty file.
33 changes: 33 additions & 0 deletions tests/resources/simulation/ipv4_icmp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: IPv4/ICMP
target: 10.0.0.107
protocol: Icmp
icmp_identifier: 1
hops:
- ttl: 1
resp: !SingleHost
addr: 10.0.0.101
rtt_ms: 10
- ttl: 2
resp: !SingleHost
addr: 10.0.0.102
rtt_ms: 20
- ttl: 3
resp: !SingleHost
addr: 10.0.0.103
rtt_ms: 30
- ttl: 4
resp: !SingleHost
addr: 10.0.0.104
rtt_ms: 40
- ttl: 5
resp: !SingleHost
addr: 10.0.0.105
rtt_ms: 50
- ttl: 6
resp: !SingleHost
addr: 10.0.0.106
rtt_ms: 60
- ttl: 7
resp: !SingleHost
addr: 10.0.0.107
rtt_ms: 70
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: Simple example
name: IPv4/ICMP with 9 hops, 2 of which do not respond
target: 10.0.0.109
icmp_identifier: 314
protocol: Icmp
icmp_identifier: 3
hops:
- ttl: 1
resp: !SingleHost
Expand Down Expand Up @@ -29,7 +30,7 @@ hops:
addr: 10.0.0.107
rtt_ms: 20
- ttl: 8
resp: !NoResponse
resp: NoResponse
- ttl: 9
resp: !SingleHost
addr: 10.0.0.109
Expand Down
25 changes: 25 additions & 0 deletions tests/resources/simulation/ipv4_icmp_ooo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: IPv4/ICMP with out of order responses
target: 10.0.0.105
protocol: Icmp
icmp_identifier: 4
hops:
- ttl: 1
resp: !SingleHost
addr: 10.0.0.101
rtt_ms: 20
- ttl: 2
resp: !SingleHost
addr: 10.0.0.102
rtt_ms: 15
- ttl: 3
resp: !SingleHost
addr: 10.0.0.103
rtt_ms: 10
- ttl: 4
resp: !SingleHost
addr: 10.0.0.104
rtt_ms: 5
- ttl: 5
resp: !SingleHost
addr: 10.0.0.105
rtt_ms: 0
17 changes: 17 additions & 0 deletions tests/resources/simulation/ipv4_tcp_fixed_dest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: IPv4/TCP with a fixed dest port
target: 10.0.0.103
protocol: Tcp
port_direction: !FixedDest 80
hops:
- ttl: 1
resp: !SingleHost
addr: 10.0.0.101
rtt_ms: 10
- ttl: 2
resp: !SingleHost
addr: 10.0.0.102
rtt_ms: 20
- ttl: 3
resp: !SingleHost
addr: 10.0.0.103
rtt_ms: 20
18 changes: 18 additions & 0 deletions tests/resources/simulation/ipv4_udp_classic_fixed_dest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: IPv4/UDP classic with a fixed dest port
target: 10.0.0.103
protocol: Udp
port_direction: !FixedDest 33000
multipath_strategy: Classic
hops:
- ttl: 1
resp: !SingleHost
addr: 10.0.0.101
rtt_ms: 10
- ttl: 2
resp: !SingleHost
addr: 10.0.0.102
rtt_ms: 20
- ttl: 3
resp: !SingleHost
addr: 10.0.0.103
rtt_ms: 20
18 changes: 18 additions & 0 deletions tests/resources/simulation/ipv4_udp_classic_fixed_src.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: IPv4/UDP classic with a fixed src port
target: 10.0.0.103
protocol: Udp
port_direction: !FixedSrc 5000
multipath_strategy: Classic
hops:
- ttl: 1
resp: !SingleHost
addr: 10.0.0.101
rtt_ms: 10
- ttl: 2
resp: !SingleHost
addr: 10.0.0.102
rtt_ms: 20
- ttl: 3
resp: !SingleHost
addr: 10.0.0.103
rtt_ms: 20
20 changes: 20 additions & 0 deletions tests/resources/simulation/ipv4_udp_paris_fixed_both.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: IPv4/UDP Paris with a fixed src and dest port
target: 10.0.0.103
protocol: Udp
port_direction: !FixedBoth
src: 5000
dest: 33000
multipath_strategy: Paris
hops:
- ttl: 1
resp: !SingleHost
addr: 10.0.0.101
rtt_ms: 10
- ttl: 2
resp: !SingleHost
addr: 10.0.0.102
rtt_ms: 20
- ttl: 3
resp: !SingleHost
addr: 10.0.0.103
rtt_ms: 20
Binary file added tests/resources/wintun.dll
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/sim/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#![cfg(feature = "sim-tests")]
mod network;
mod simulation;
mod tests;
mod tracer;
mod tun_device;
Loading

0 comments on commit a21e59c

Please sign in to comment.