This project combines WebAssembly (Wasm), eBPF, and Docker to create a system for monitoring network activities such as ping, traceroute, and iperf. The WebAssembly module handles the user’s network test requests, while eBPF traces the relevant system calls to gather metrics, such as average round-trip time (RTT), packet loss, and bandwidth. Docker provides a containerized environment for running the project.
- Features
- Architecture
- Project Structure
- Requirements
- Installation and Setup
- Running the Project
- Network Test Types
- Expected Output
- License
- WebAssembly: Handles user requests for network tests (ping, traceroute, iperf).
- eBPF: Monitors network traffic and collects statistics (e.g., RTT, hops, bandwidth).
- Docker: Isolates the application for portability and ensures the same behavior across environments.
- UI Ready: The project is designed to integrate with a simple user interface (UI) that allows users to select network tests and view results in real-time.
This project is divided into three main components:
- User Interface (Optional): Allows users to select the type of network test they want to run (ping, traceroute, iperf).
- WebAssembly Module: Delegates the user's network test request to the underlying system and returns the results. Compiled from Rust code into a WebAssembly binary.
- eBPF: Runs in the background and monitors network activities such as RTT, hops, bandwidth, etc., using kernel-level probes.
eBPF-Wasm-Network-Test/
├── Dockerfile # Dockerfile to build the environment
├── README.md # Project documentation
├── .gitignore # Git ignored files
├── src/ # Rust WebAssembly source code
│ ├── main.rs # Rust code for WebAssembly
├── wasm/ # Compiled WebAssembly files
│ └── network_test.wasm # Final WebAssembly binary
├── monitor_network.py # eBPF monitoring Python script
└── scripts/ # Additional helper scripts
└── run_tests.sh # Bash script to run network tests
To run this project, you need:
- Docker: Install Docker here.
- Rust: Install Rust here to build the WebAssembly module.
- Python 3: Required to run the eBPF monitoring script.
- Linux headers: Ensure that your system has the necessary kernel headers for eBPF.
Follow these steps to set up the project:
- Clone the Repository: Clone the GitHub repository to your local machine.
git clone https://github.com/harshilshah2501/eBPF-Wasm-Network-Test.git
cd eBPF-Wasm-Network-Test- Install Rust and Build the WebAssembly Module: Install Rust and build the WebAssembly module using the wasm32-wasi target.
rustup target add wasm32-wasi
cargo build --target wasm32-wasi --releaseThe compiled Wasm file will be located in target/wasm32-wasi/release/network_test.wasm.
- Build the Docker Image: Build the Docker container that will run the WebAssembly and eBPF components.
sudo docker build -t wasm-ebpf-container .- Run the Docker Container: Run the Docker container with privileged access (required for eBPF).
sudo docker run --privileged --rm wasm-ebpf-containerOnce the Docker container is up and running, you can trigger various network tests (ping, traceroute, iperf) via the WebAssembly module, and the eBPF program will collect statistics on the network activity.
- Choose a Network Test:
You can use a script or integrate the WebAssembly module with a UI to choose between different network tests (ping, traceroute, iperf).
If using a script, you can create a simple bash script (scripts/run_tests.sh) to run each test:
#!/bin/bash
echo "Running Ping Test"
curl https://example.comThe following network tests can be run via the WebAssembly module:
-
Ping: • Measures the Round-Trip Time (RTT) between your system and a destination host. • eBPF collects the RTT for each packet and reports the average time.
-
Traceroute: • Determines the number of hops between your system and a destination host. • eBPF monitors each hop’s RTT and displays the path taken.
-
Iperf: • Measures the bandwidth between two systems. • eBPF tracks the bandwidth usage during the iperf test.
When running the project, you should see the following types of output:
- WebAssembly: Outputs the test result header, e.g., Running Ping Test....
- eBPF: Prints detailed information about the network test, such as: • Ping: Packet caught! Average RTT: 20ms • Traceroute: Hop 1: 10ms, Hop 2: 15ms, Hop 3: 30ms • Iperf: Bandwidth: 100Mbps
Hello from WebAssembly!
Tracing network packets... Press Ctrl+C to stop.
Packet caught! Average RTT: 20ms
Packet caught! Average RTT: 22msThis project is licensed under the MIT License. Feel free to use it as you like, but please provide proper attribution.
• This project currently uses Python’s BCC (BPF Compiler Collection) to monitor network tests via eBPF. You can extend the project by integrating additional network tools or metrics. • Future improvements could include adding a UI layer for ease of use and visualizing the network test results.