Skip to main content

NetworkTopologyMapper

Struct NetworkTopologyMapper 

Source
pub struct NetworkTopologyMapper { /* private fields */ }
Expand description

Live network topology mapper.

Tracks peer nodes and directed edges, computes graph algorithms, and maintains a bounded ring-buffer of snapshots.

Implementations§

Source§

impl NetworkTopologyMapper

Source

pub fn new(config: NtmMapperConfig) -> Self

Create a new mapper with the given config.

Source

pub fn with_defaults() -> Self

Create a mapper with default configuration.

Source

pub fn add_node( &mut self, id: NtmNodeId, addr: impl Into<String>, region: Option<String>, rtt_ms: f64, last_seen: u64, ) -> Result<(), NtmMapperError>

Insert or update a node.

If the node already exists its addr, region, rtt_ms, and last_seen fields are refreshed. Returns Err(CapacityExceeded) when the node is new and the graph is full.

Source

pub fn remove_node(&mut self, id: &NtmNodeId) -> Result<(), NtmMapperError>

Remove a node and all edges incident to it.

Source

pub fn update_node_rtt( &mut self, id: &NtmNodeId, rtt_ms: f64, ) -> Result<(), NtmMapperError>

Update the RTT measurement for an existing node.

Source

pub fn set_bootstrap( &mut self, id: &NtmNodeId, flag: bool, ) -> Result<(), NtmMapperError>

Mark a node as a bootstrap / well-known anchor.

Source

pub fn get_node(&self, id: &NtmNodeId) -> Option<&NtmNode>

Return an immutable reference to a node.

Source

pub fn nodes(&self) -> impl Iterator<Item = &NtmNode>

Iterate over all nodes.

Source

pub fn add_edge( &mut self, src: NtmNodeId, dst: NtmNodeId, latency_ms: f64, bandwidth_kbps: f64, observed_at: u64, ) -> Result<NtmEdgeId, NtmMapperError>

Insert a directed edge src → dst.

If an edge with the same (src, dst) pair already exists, its latency_ms, bandwidth_kbps, and observed_at fields are updated. Returns the edge identifier.

Source

pub fn remove_edge(&mut self, id: NtmEdgeId) -> Result<(), NtmMapperError>

Remove a directed edge by its identifier.

Source

pub fn update_edge_latency( &mut self, id: NtmEdgeId, latency_ms: f64, ) -> Result<(), NtmMapperError>

Update the latency measurement for an existing edge.

Source

pub fn get_edge(&self, id: NtmEdgeId) -> Option<&NtmEdge>

Return an immutable reference to an edge.

Source

pub fn find_edge(&self, src: &NtmNodeId, dst: &NtmNodeId) -> Option<NtmEdgeId>

Return the edge identifier for the directed pair (src, dst), if any.

Source

pub fn edges(&self) -> impl Iterator<Item = &NtmEdge>

Iterate over all edges.

Source

pub fn neighbors(&self, node_id: &NtmNodeId) -> Vec<NtmNodeId>

Return the neighbour node ids reachable via outgoing edges from node_id.

Source

pub fn shortest_path( &self, src: &NtmNodeId, dst: &NtmNodeId, ) -> Option<Vec<NtmNodeId>>

Dijkstra shortest path from src to dst weighted by latency_ms.

Returns None if either node is unknown or no path exists.

Source

pub fn bfs_distance(&self, src: &NtmNodeId, dst: &NtmNodeId) -> Option<u32>

BFS-based shortest path counting hops (ignores weights).

Returns None if no path exists.

Source

pub fn diameter(&self) -> u32

Graph diameter: maximum of all pairwise BFS distances.

Returns 0 when the graph has fewer than two nodes.

Source

pub fn clustering_coefficient(&self, node_id: &NtmNodeId) -> f64

Local clustering coefficient for node_id.

C(u) = triangles / (k * (k-1)) where k = degree(u). Returns 0.0 for nodes with degree < 2.

Source

pub fn compute_betweenness_centrality(&self) -> HashMap<NtmNodeId, f64>

Brandes algorithm for betweenness centrality on the directed graph.

Complexity O(V * E) — suitable for moderate-sized graphs (≤ 4096 nodes).

Source

pub fn take_snapshot(&mut self, ts: u64) -> NtmSnapshot

Capture the current state into a snapshot and store it.

If the snapshot buffer is full (20 entries) the oldest entry is dropped before the new one is inserted.

Source

pub fn snapshots(&self) -> &VecDeque<NtmSnapshot>

Access the snapshot history (oldest first).

Source

pub fn prune_stale(&mut self, now_ts: u64)

Remove all nodes (and their edges) whose last_seen is older than now_ts - config.prune_disconnected_after_secs.

Source

pub fn topology_stats(&self) -> NtmTopologyMetrics

Compute the full suite of topology metrics.

Source

pub fn node_count(&self) -> usize

Return the number of nodes.

Source

pub fn edge_count(&self) -> usize

Return the number of edges.

Source

pub fn config(&self) -> &NtmMapperConfig

Return the current configuration.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more