pub(crate) mod ingest;
pub(crate) use ingest::InjestableEvents;
use std::{cmp::Reverse, collections::BinaryHeap};
use crate::{Jiffies, MessagePtr, Pid, TimerId};
pub(crate) enum NetworkFsm {
KeepLatency,
KeepBandwidth,
}
pub(crate) enum Event {
Fault(FaultEvents),
Handler(PidHandlerEvent),
}
pub(crate) enum FaultEvents {
BreakLink { pid1: Pid, pid2: Pid },
RestoreLink { pid1: Pid, pid2: Pid },
Isolate { pid: Pid },
FinishIsolation { pid: Pid },
}
pub(crate) enum PidHandlerEvent {
Start {
pid: Pid,
},
Network {
source: Pid,
target: Pid,
message: MessagePtr,
fsm: NetworkFsm,
},
Timer {
pid: Pid,
id: TimerId,
},
}
impl PidHandlerEvent {
pub(crate) fn target_pid(&self) -> Pid {
match self {
Self::Start { pid } => *pid,
Self::Network { target, .. } => *target,
Self::Timer { pid, .. } => *pid,
}
}
}
pub(crate) struct TimedEvent {
pub(crate) invocation_time: Jiffies,
pub(crate) event: Event,
}
impl PartialEq for TimedEvent {
fn eq(&self, other: &Self) -> bool {
self.invocation_time.eq(&other.invocation_time)
}
}
impl Eq for TimedEvent {}
impl PartialOrd for TimedEvent {
fn ge(&self, other: &Self) -> bool {
self.invocation_time.ge(&other.invocation_time)
}
fn le(&self, other: &Self) -> bool {
self.invocation_time.le(&other.invocation_time)
}
fn gt(&self, other: &Self) -> bool {
self.invocation_time.gt(&other.invocation_time)
}
fn lt(&self, other: &Self) -> bool {
self.invocation_time.lt(&other.invocation_time)
}
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
self.invocation_time.partial_cmp(&other.invocation_time)
}
}
impl Ord for TimedEvent {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.invocation_time.cmp(&other.invocation_time)
}
}
pub(crate) type EventQueue = BinaryHeap<Reverse<TimedEvent>>;