pub(crate) mod ingest;
pub(crate) use ingest::InjestableEvents;
use std::{cmp::Reverse, collections::BinaryHeap};
use crate::{Jiffies, MessagePtr, Rank, TimerId};
pub(crate) enum NetworkFsm {
KeepLatency,
KeepBandwidth,
}
pub(crate) enum Event {
Fault(FaultEvents),
Handler(RankHandlerEvent),
}
pub(crate) enum FaultEvents {
BreakLink { rank1: Rank, rank2: Rank },
RestoreLink { rank1: Rank, rank2: Rank },
Isolate { rank: Rank },
FinishIsolation { rank: Rank },
}
pub(crate) enum RankHandlerEvent {
Start {
rank: Rank,
},
Network {
source: Rank,
target: Rank,
message: MessagePtr,
fsm: NetworkFsm,
},
Timer {
rank: Rank,
id: TimerId,
},
}
impl RankHandlerEvent {
pub(crate) fn target_rank(&self) -> Rank {
match self {
Self::Start { rank } => *rank,
Self::Network { target, .. } => *target,
Self::Timer { rank, .. } => *rank,
}
}
}
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>>;