Expand description
§mabi-chaos
Chaos engineering module for the OT protocol simulator.
This crate provides a trait-based, extensible chaos engineering framework for testing the resilience of industrial protocol clients and systems.
§Architecture
The chaos module is built around several key abstractions:
Fault: Core trait that all fault types implementFaultContext: Execution context for fault injection- [
FaultInjector]: Manages fault application to requests/responses ChaosEngine: Orchestrates multiple faults and schedules- [
Middleware]: Transparent fault injection layer
§Fault Categories
§Network Faults (network)
- Latency injection (constant, uniform, normal, log-normal)
- Packet loss (random, burst)
- Connection disruption (disconnect, timeout, reset)
- Bandwidth throttling
§Device Faults (device)
- Device offline simulation
- Slow response injection
- Corrupted data responses
- State transition failures
§Protocol Faults (protocol)
- Malformed packets
- Invalid checksums
- Out-of-order responses
- Timeout simulation
§Usage
§Basic Usage
ⓘ
use mabi_chaos::prelude::*;
// Create a latency fault
let latency = NetworkLatencyFault::builder()
.base_ms(100)
.jitter_ms(50)
.distribution(LatencyDistribution::Normal)
.build();
// Create chaos engine
let engine = ChaosEngine::builder()
.add_fault("latency", latency)
.build();
// Apply to a target
engine.enable("latency", "device-001").await;§Scheduled Chaos
ⓘ
use mabi_chaos::prelude::*;
let schedule = ChaosSchedule::builder()
.name("resilience-test")
.add_entry(ChaosEntry::builder()
.start_secs(0.0)
.duration_secs(60.0)
.fault(ChaosType::NetworkLatency { base_ms: 100, jitter_ms: 50 })
.target("modbus-*")
.build())
.build();
let scheduler = ChaosScheduler::new(schedule);
scheduler.start();§Middleware Pattern
ⓘ
use mabi_chaos::middleware::ChaosMiddleware;
let middleware = ChaosMiddleware::new(engine);
// Wrap device operations
let result = middleware.wrap_read(device, point_id).await;Re-exports§
pub use error::ChaosError;pub use error::ChaosResult;pub use fault::Fault;pub use fault::FaultBehavior;pub use fault::FaultSeverity;pub use fault::FaultState;pub use fault::FaultMetadata;pub use context::FaultContext;pub use context::FaultContextBuilder;pub use context::RequestPhase;pub use context::TargetInfo;pub use registry::FaultRegistry;pub use registry::FaultEntry;pub use registry::FaultFilter;pub use engine::ChaosEngine;pub use engine::ChaosEngineBuilder;pub use engine::EngineState;pub use engine::EngineEvent;pub use middleware::ChaosMiddleware;pub use middleware::MiddlewareConfig;pub use middleware::MiddlewareResult;pub use scheduler::ChaosScheduler;pub use scheduler::ChaosSchedule;pub use scheduler::ChaosEntry;pub use scheduler::ChaosType;pub use scheduler::ActiveChaos;pub use scheduler::ChaosEvent;pub use scheduler::ScheduleState;pub use network::NetworkLatencyFault;pub use network::LatencyConfig;pub use network::LatencyDistribution;pub use network::PacketLossFault;pub use network::PacketLossConfig;pub use network::BurstConfig;pub use network::ConnectionFault;pub use network::DisconnectMode;pub use network::ConnectionConfig;pub use network::BandwidthFault;pub use network::BandwidthConfig;pub use device::DeviceOfflineFault;pub use device::OfflineConfig;pub use device::OfflinePattern;pub use device::SlowResponseFault;pub use device::SlowResponseConfig;pub use device::CorruptedDataFault;pub use device::CorruptionConfig;pub use device::CorruptionStrategy;pub use device::StateTransitionFault;pub use device::TransitionConfig;pub use protocol::MalformedPacketFault;pub use protocol::MalformedConfig;pub use protocol::MalformationType;pub use protocol::ChecksumFault;pub use protocol::ChecksumConfig;pub use protocol::TimeoutFault;pub use protocol::TimeoutConfig;pub use protocol::TimeoutPattern;pub use protocol::ReorderFault;pub use protocol::ReorderConfig;pub use bacnet::ApduFault;pub use bacnet::ApduFaultConfig;pub use bacnet::ApduFaultType;pub use bacnet::ServiceFault;pub use bacnet::ServiceFaultConfig;pub use bacnet::ServiceFaultType;pub use bacnet::CovFault;pub use bacnet::CovFaultConfig;pub use bacnet::CovFaultType;pub use bacnet::PropertyFault;pub use bacnet::PropertyFaultConfig;pub use bacnet::PropertyFaultType;pub use bacnet::SegmentationFault;pub use bacnet::SegmentationFaultConfig;pub use bacnet::SegmentationFaultType;pub use config::ChaosConfig;pub use config::FaultConfig;pub use config::ScheduleConfig;pub use config::GlobalConfig;
Modules§
- bacnet
- BACnet/IP protocol-specific fault implementations.
- config
- Configuration types for the chaos engineering module.
- context
- Fault context for carrying request/response information.
- device
- Device fault implementations.
- engine
- Chaos engine for orchestrating fault injection.
- error
- Error types for the chaos engineering module.
- fault
- Core fault trait and related types.
- middleware
- Middleware for transparent fault injection.
- network
- Network fault implementations.
- prelude
- Prelude module for convenient imports.
- protocol
- Protocol fault implementations.
- registry
- Fault registry for managing fault instances.
- scheduler
- Chaos scheduler for time-based fault injection.