pub struct AdaptiveRoutingEngine { /* private fields */ }Expand description
An adaptive, multi-path routing engine for IPFRS network nodes.
Maintains per-destination route tables with real-time metrics updated via
EWMA and selects the best next-hop according to a configurable
RoutingPolicy.
Implementations§
Source§impl AdaptiveRoutingEngine
impl AdaptiveRoutingEngine
Sourcepub fn new(config: AdaptiveRoutingConfig) -> Self
pub fn new(config: AdaptiveRoutingConfig) -> Self
Create a new engine with the supplied configuration.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create an engine with default configuration.
Sourcepub fn add_route(&mut self, key: RouteKey, entry: RouteEntry)
pub fn add_route(&mut self, key: RouteKey, entry: RouteEntry)
Add or overwrite a route entry for the given key.
If max_routes_per_key is reached the entry with the worst score is
replaced.
Sourcepub fn remove_route(&mut self, key: &RouteKey, next_hop: &[u8; 32])
pub fn remove_route(&mut self, key: &RouteKey, next_hop: &[u8; 32])
Remove all routes for the given key that use next_hop.
Sourcepub fn clear_routes(&mut self, key: &RouteKey)
pub fn clear_routes(&mut self, key: &RouteKey)
Remove every route entry associated with key.
Sourcepub fn routes_for(&self, key: &RouteKey) -> Option<&[RouteEntry]>
pub fn routes_for(&self, key: &RouteKey) -> Option<&[RouteEntry]>
Return an immutable slice of route entries for a key, if any.
Sourcepub fn update_metrics(
&mut self,
key: &RouteKey,
next_hop: &[u8; 32],
rtt_ms: f64,
loss: f64,
) -> Result<(), RoutingEngineError>
pub fn update_metrics( &mut self, key: &RouteKey, next_hop: &[u8; 32], rtt_ms: f64, loss: f64, ) -> Result<(), RoutingEngineError>
Apply an EWMA update to RTT and loss metrics for a specific next-hop.
§Errors
Returns Err if the key or next-hop is not found in the route table.
Sourcepub fn update_bandwidth(
&mut self,
key: &RouteKey,
next_hop: &[u8; 32],
bandwidth_kbps: f64,
) -> Result<(), RoutingEngineError>
pub fn update_bandwidth( &mut self, key: &RouteKey, next_hop: &[u8; 32], bandwidth_kbps: f64, ) -> Result<(), RoutingEngineError>
Update only the bandwidth estimate for a specific next-hop.
Sourcepub fn select_next_hop(
&self,
key: &RouteKey,
policy: RoutingPolicy,
) -> Option<[u8; 32]>
pub fn select_next_hop( &self, key: &RouteKey, policy: RoutingPolicy, ) -> Option<[u8; 32]>
Select the best next-hop peer for key according to policy.
Returns None if no routes are recorded for the key or all entries are
unhealthy.
Sourcepub fn select_next_hop_default(&self, key: &RouteKey) -> Option<[u8; 32]>
pub fn select_next_hop_default(&self, key: &RouteKey) -> Option<[u8; 32]>
Select using the engine’s current active policy.
Sourcepub fn set_policy(&mut self, policy: RoutingPolicy)
pub fn set_policy(&mut self, policy: RoutingPolicy)
Switch the active routing policy, incrementing the policy-switch counter.
Sourcepub fn active_policy(&self) -> RoutingPolicy
pub fn active_policy(&self) -> RoutingPolicy
Return the currently active routing policy.
Sourcepub fn probe_routes(&mut self)
pub fn probe_routes(&mut self)
Simulate a probe round: apply synthetic RTT perturbations to all routes using xorshift64-based PRNG.
In production this would send real probe packets; here we perturb existing RTT estimates to model jitter and update weights accordingly.
Sourcepub fn run_adaptation_cycle(&mut self)
pub fn run_adaptation_cycle(&mut self)
Prune stale route entries and recompute all weights.
An entry is considered stale if it hasn’t been updated for more than
probe_interval_secs × 3 seconds.
Sourcepub fn routing_stats(&self) -> AdaptiveRoutingStats
pub fn routing_stats(&self) -> AdaptiveRoutingStats
Return a snapshot of current engine statistics.
Sourcepub fn entry_count(&self) -> usize
pub fn entry_count(&self) -> usize
Return the total number of route entries across all keys.
Sourcepub fn has_route(&self, key: &RouteKey, next_hop: &[u8; 32]) -> bool
pub fn has_route(&self, key: &RouteKey, next_hop: &[u8; 32]) -> bool
Check whether a route exists for the given key and next-hop.
Sourcepub fn next_hops_for(&self, key: &RouteKey) -> Vec<[u8; 32]>
pub fn next_hops_for(&self, key: &RouteKey) -> Vec<[u8; 32]>
Return all distinct next-hops recorded for key.
Sourcepub fn best_entry(
&self,
key: &RouteKey,
policy: RoutingPolicy,
) -> Option<RouteEntry>
pub fn best_entry( &self, key: &RouteKey, policy: RoutingPolicy, ) -> Option<RouteEntry>
Return the best route entry for key under the given policy (clone).
Sourcepub fn route_table(&self) -> &HashMap<RouteKey, Vec<RouteEntry>>
pub fn route_table(&self) -> &HashMap<RouteKey, Vec<RouteEntry>>
Return a reference to the underlying route table.
Sourcepub fn merge_from(&mut self, other: &AdaptiveRoutingEngine)
pub fn merge_from(&mut self, other: &AdaptiveRoutingEngine)
Merge another engine’s route table into this one.
Sourcepub fn resize_max_routes(&mut self, new_max: usize)
pub fn resize_max_routes(&mut self, new_max: usize)
Resize max_routes_per_key and evict excess entries if needed.
Sourcepub fn set_probe_interval(&mut self, secs: u64)
pub fn set_probe_interval(&mut self, secs: u64)
Update the probe interval.
Auto Trait Implementations§
impl Freeze for AdaptiveRoutingEngine
impl RefUnwindSafe for AdaptiveRoutingEngine
impl Send for AdaptiveRoutingEngine
impl Sync for AdaptiveRoutingEngine
impl Unpin for AdaptiveRoutingEngine
impl UnsafeUnpin for AdaptiveRoutingEngine
impl UnwindSafe for AdaptiveRoutingEngine
Blanket Implementations§
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more