Skip to content

Commit

Permalink
Test harness upgrades (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
jarpoole authored Nov 7, 2022
1 parent de9a70e commit 7eee22d
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 16 deletions.
1 change: 0 additions & 1 deletion backend/etherweasel_rs_container/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM ubuntu:latest

RUN ls
RUN apt-get update
# Install networking binaries
RUN apt-get install -y iproute2 iptables curl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@ use async_trait::async_trait;
use futures::stream::TryStreamExt;
use rtnetlink::{new_connection, Error, Handle};

pub struct DockerDriverConfig {
pub ethernet_a: &'static str,
pub ethernet_b: &'static str,
pub interface_a: &'static str,
pub interface_b: &'static str,
pub bridge_a: &'static str,
pub bridge_b: &'static str,
pub bridge_ab: &'static str,
}

pub struct DockerDriver {
config: DockerDriverConfig,
mode: DriverMode,
}

impl DockerDriver {
pub fn new() -> Self {
pub fn new(config: DockerDriverConfig) -> Self {
Self {
mode: DriverMode::DISCONNECTED,
config,
}
}
}
Expand All @@ -24,21 +36,21 @@ impl Driver for DockerDriver {

if mode == DriverMode::ACTIVE {
// Bridge veth and tap A
set_interface_master(&handle, "ethmitmA", "brA").await?;
set_interface_master(&handle, "tapA", "brA").await?;
set_interface_master(&handle, self.config.ethernet_a, self.config.bridge_a).await?;
set_interface_master(&handle, self.config.interface_a, self.config.bridge_a).await?;
// Bridge veth and tap B
set_interface_master(&handle, "ethmitmB", "brB").await?;
set_interface_master(&handle, "tapB", "brB").await?;
set_interface_master(&handle, self.config.ethernet_b, self.config.bridge_b).await?;
set_interface_master(&handle, self.config.interface_b, self.config.bridge_b).await?;
// Bring both taps up
set_interface_up(&handle, "tabA").await?;
set_interface_up(&handle, "tabB").await?;
set_interface_up(&handle, self.config.interface_a).await?;
set_interface_up(&handle, self.config.interface_b).await?;
// Update the local state
self.mode = DriverMode::ACTIVE;
} else {
set_interface_nomaster(&handle, "tapA").await?;
set_interface_nomaster(&handle, "tapB").await?;
set_interface_master(&handle, "ethmitmA", "brAB").await?;
set_interface_master(&handle, "ethmitmB", "brAB").await?;
set_interface_nomaster(&handle, self.config.interface_a).await?;
set_interface_nomaster(&handle, self.config.interface_b).await?;
set_interface_master(&handle, self.config.ethernet_a, self.config.bridge_ab).await?;
set_interface_master(&handle, self.config.ethernet_b, self.config.bridge_ab).await?;
self.mode = DriverMode::PASSIVE;
}

Expand Down
14 changes: 12 additions & 2 deletions backend/etherweasel_rs_container/etherweasel_rs/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use axum::{
};
use clap::{Parser, ValueEnum};
use driver::{
docker_driver::DockerDriver,
docker_driver::{DockerDriver,DockerDriverConfig},
driver::{DriverGuard, DriverMode},
hardware_driver::HardwareDriver,
mock_driver::MockDriver,
Expand Down Expand Up @@ -82,7 +82,17 @@ async fn main() {
let args = Cli::parse();
let driver_guard: DriverGuard = Arc::new(Mutex::new(match args.driver {
Driver::MOCK => Box::new(MockDriver::new()),
Driver::DOCKER => Box::new(DockerDriver::new()),
Driver::DOCKER => Box::new(DockerDriver::new(
DockerDriverConfig{
ethernet_a: "ethmitmA",
ethernet_b: "ethmitmB",
interface_a: "tapA",
interface_b: "tapB",
bridge_a: "brA",
bridge_b: "brB",
bridge_ab: "brAB",
}
)),
Driver::HARDWARE => Box::new(HardwareDriver::new(SPI_INTERFACE)),
}));
let driver_mode = match args.mode {
Expand Down
2 changes: 1 addition & 1 deletion backend/etherweasel_rs_container/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ if [[ $TARGET = "docker" ]]; then
--memory="$MEMORY_LIMIT" \
"$( if [[ "$INTERACTIVE" = true ]]; then echo "--detach=false"; else echo "--detach=true"; fi )" \
"$( ../utils/synchronize.sh etherweasel_rs_backend_instance mount )" \
etherweasel_rs_backend_build --driver=mock "$@"
etherweasel_rs_backend_build --driver=docker "$@"
fi

if [[ $TARGET = "local" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion backend/testharness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ elif [[ $TESTMODE = "iperf" ]]; then
elif [[ $TESTMODE = "dns" ]]; then
# Build and run
./dns_container/run.sh
./etherweasel_rs_container/run.sh docker -- --driver=docker --mode=active
./etherweasel_rs_container/run.sh docker -- --mode=active
./server_container/run.sh bind
# Setup networking
./utils/network.sh \
Expand Down

0 comments on commit 7eee22d

Please sign in to comment.