proto-lab
Lightweight & Deterministic Network Protocol Simulator
proto-lab is a simple yet powerful simulator designed for developing and testing custom networking protocols without requiring physical hardware. It provides a deterministic environment for automated testing, protocol experimentation, and multi-threaded simulations.
This library simulates the physical layer of networking, including modems and ethers that connect them.
π’ Note: proto-lab only handles raw byte transmission between modemsβit does not implement IP, TCP, UDP, or any higher-layer protocols. Instead, it serves as a foundation for building and testing such protocols.
Key Features
- π Develop & test protocols without needing real hardware.
- π§ͺ Automate testing scenarios with full deterministic control.
- β‘ Simulate data collisions when multiple modems transmit in the same ether at the same tick.
- π‘ Multi-ether support β Modems can operate across multiple ethers at once.
- π Chained data transfer β Simulate multi-hop data relay across devices.
- π Dynamic topology β Simulate modems being hot-plugged or removed mid-transmission.
- π§΅ Thread-safe modem cloning β Clone modems to different threads while sharing state.
- β³ Flexible tick-based updates β Control simulation timing manually or run in automatic background mode.
How It Works
proto-lab operates in discrete ticks, ensuring deterministic simulation behavior:
- Start a Tick β
start_tick()initializes transmission & listening states for modems. - Simulate a Step β
simulate()processes modem transmissions and delivers bytes to listening modems. - End a Tick β
stop_tick()finalizes transmission, queues received bytes, and prepares for the next step.
You can control ticks manually or let proto-lab handle updates via start_simulation_thread() and stop_simulation_thread().
Simulation Process in Detail
start_tick() - Begins a new tick cycle:
Iterates through all modems in ethers.
Each sender modem prepares bytes for transmission.
Each receiver modem enters listening mode.
simulate() - Runs the simulation step:
Identifies broadcasting modems.
Transfers broadcasted bytes to all listening modems.
stop_tick() - Ends the tick cycle:
Iterates through all modems in ethers.
Each sender modem stops broadcasting.
Each receiver modem queues received bytes.
Full Example: Simulating a Mesh Network
proto-lab seamlessly integrates into complex network simulations, including mesh protocols.
Below is a simplified example demonstrating multi-ether communication and node interaction:
use ;
Getting Started
Add proto-lab to your Cargo.toml:
[dependencies]
proto-lab = "0.1"
Explore the API and start building your protocol simulations.
Run tests and fine-tune your protocol logic with deterministic control.
Contribute
proto-lab is a fresh project, and contributions are welcome! Feel free to submit pull requests, report issues, or suggest new features.
π Note: Currently, virtual modems support only embedded-io traits. Contributions adding support for other traits are encouraged! License
proto-lab is released under the GPL v3.0 license.