46 lines
1.4 KiB
Markdown
46 lines
1.4 KiB
Markdown
# SQ-019: Virtual Network for Simulation
|
|
|
|
**Status:** `[x] DONE`
|
|
**Blocked by:** SQ-003
|
|
**Priority:** Medium
|
|
|
|
## Description
|
|
|
|
Virtual network layer for multi-node simulation testing. Enables partition, latency, and packet drop injection.
|
|
|
|
## Files to Create/Modify
|
|
|
|
- `crates/sq-sim/src/network.rs` - VirtualNetwork with message queues and fault injection
|
|
|
|
## VirtualNetwork API
|
|
|
|
```rust
|
|
pub struct VirtualNetwork {
|
|
queues: HashMap<(NodeId, NodeId), VecDeque<Vec<u8>>>,
|
|
partitions: HashSet<(NodeId, NodeId)>,
|
|
latency: Option<(Duration, Duration)>, // min, max
|
|
drop_probability: f64,
|
|
}
|
|
|
|
impl VirtualNetwork {
|
|
pub fn new() -> Self;
|
|
pub fn partition(&mut self, a: NodeId, b: NodeId);
|
|
pub fn heal(&mut self, a: NodeId, b: NodeId);
|
|
pub fn heal_all(&mut self);
|
|
pub fn set_latency(&mut self, min: Duration, max: Duration);
|
|
pub fn set_drop_probability(&mut self, prob: f64);
|
|
pub async fn send(&self, from: NodeId, to: NodeId, msg: Vec<u8>) -> Result<()>;
|
|
pub async fn recv(&self, node: NodeId) -> Result<(NodeId, Vec<u8>)>;
|
|
pub fn deliver_pending(&mut self); // Process queued messages
|
|
}
|
|
```
|
|
|
|
## Acceptance Criteria
|
|
|
|
- [ ] Two virtual nodes exchange messages successfully
|
|
- [ ] Partition: messages from A to B are dropped
|
|
- [ ] Heal: messages resume flowing after heal
|
|
- [ ] Latency injection: messages are delayed
|
|
- [ ] Drop probability: some messages are randomly dropped
|
|
- [ ] Bidirectional partition: neither direction works
|